I have a design question. I have a class hierarchy:
- AbstractEntity
- NPC extends AbstractEntity implements LifeForm
- Player extends AbstractEntity implements LifeForm
There is a method #moveTo(Target target). This method exists currently in both Player and NPC.
The implemetation is the same for both classes. Only one method called (getQueuedActions()) has a different implementation.
So, in theory, the whole method can be implemented at AbstractEntity, and the concrete difference is implemented at the child class level. But the Java compiler says: getQueuedActions() needs to be implemented also at AbstractEntity. I could of course do an instace of check and implement accordinly. But I thought I ask here, for I think I have something wrong here.
Is there a way to implement the method in Java indicating that yes, this does exist at AbstractEntity but look at the concrete (sub-)class for the real implementation? In Smalltalk, you would do ^implementedBySubClass. To explain, #implementedBySubClass is a way of defining a method as abstract at one level of the class hierarchy but still support a certain protocol (or interface) while not having a real implementation.
Is there an equivalent in Java?