I'm currently trying to reorganize my code after reading that implementation is preferable to extensions. I'm currently trying to create a function that adds an object to the scene. To better define what each object is, there are several lists, such as a list for updating, rendering, etc.
private List<Updatable> updatables;
private List<Removable> removables;
private List<Renderable> renderables;
private List<Collidable> collidables;
I want to make a function in my Scene class as follows:
public void add(Object o) {
if(o instanceof Updatable)
updatables.add((Updatable) o);
if(o instanceof Removable)
removables.add((Removable) o);
if(o instanceof Renderable)
renderables.add((Renderable) o);
if(o instanceof Collidable)
collidables.add((Collidable) o);
}
, . , , instanceof, -, , / , ? , .