I'm trying to structure my game object classes similar to how it is done in this article. One way to implement this strategy is discussed in this StackOverflow question.
Following the strategy proposed in the linked question above, how would I control how objects are handled based on their implementations?
For example: suppose I have a base class Item and two subclasses ItemPhys and ItemStatic. These two subclasses both extend Item. ItemPhys implements the interface Moveable, but ItemStatic does not.
If all of the Item's in my game world are stored in a single ArrayList of Item objects, how do I make it so Item::update()
will only try to call Item::updateMovable()
if the Item in question implements Moveable?