Multiple operations depending on the type of the object passed

Posted by mixm on Stack Overflow See other posts from Stack Overflow or by mixm
Published on 2010-05-03T13:57:04Z Indexed on 2010/05/03 14:18 UTC
Read the original article Hit count: 236

Filed under:
|

Assuming I create a method which is passed an object and that method would perform an action depending on the object passed. How should I identify the object?

I thought of using the class name to identify the object, but that may be impractical since I could easily change the class name of objects, and generate headaches during future development. Am I right?

edit: for example, i have objects ball and bomb. if i have another object called wall, and the wall has the method to resolve collisions with the wall (e.g. the coordinates of the colliding ball and bomb) but have different logic depending on the colliding object (i.e. ball and bomb)

© Stack Overflow or respective owner

Related posts about java

Related posts about api-design