Basically, what I would like to obtain is a way to iterate through ONE list, and call methods specific to the interface the objects in the collection implement.
In my Java project, it would result in something like this:
//GameComponent would be my empty abstract class HashSet<GameComponent> components = new HashSet<GameComponent>(); components.add(/* instance of a class that extends GameComponent and implements Drawable || Updatable */); for (Drawable d : components) d.draw(); for (Updatable u : components) u.update();
My friends suggested me to just make two separate lists, but that means some objects will be in both lists.
I also think that it makes sense (abstraction-wise) to have one list of GameComponents and iterate through that one list.
But I also don't like having an empty class to inherit from, only for categorisation.
So, the question is: does my approach make sense? If so, is it elegant? If not, what pattern could I follow?