# How can I avoid type checking in the physics side of collision handling?

I have a class responsible for handling the physics side of collisions. When the collision detector spots a collision, it notifies both entities in the collision to take care of gameplay. It also notifies the PhysicsGenerator to take car of the physics of the collision.

I don't know if it's possible to avoid type checking in the handleCollision() method of PhysicsGenerator. What I wanted to do is apply a force on both entities in the collision to push them backwards. But I can only do this if they are MovingEntities. What if one of them is a StaticEntity? In this case it should be treated differently. I don't know how I can do that without using instanceof quite a lot.

How is this usually handled?

• Currently the applyForce() method is in MovingEntity. I thought about doing what you suggest: moving it up to Entity, making it abstract and having the implementation in StaticEntity do nothing. But I thought that 'conceptually', a class having a method with no implementation is somewhat inelegant. Is it something done frequently in game dev and programming generally? Is it considered okay? – Aviv Cohn Jun 21 '14 at 0:51