Ok, so I have a hierarchy of classes and subclasses. They all must have certain methods. Those methods are in an interface implemented by the superclass and everything below.
There is one method they should all have and define but that method is "in spirit", of the static kind, returning the same results for all instances of a given class.
Unfortunately, one cannot have a static method as part of an interface and also, static method do not support inheritance, they "hide" rather than "override".
So, what are the options for a static method that all classes in a hierarchy must have and that can be called in a generic way? At the moment, I made that method non static...
Also, ideally, that shouldn't involve having a second hierarchy of classes that must be kept in sync just for that one method...
Many Thanks
======
EDIT: People asked for an example so here you go:
OK, let's say i have a hierarchy of animal classes (abstract Animal class > abstract Mammal class > Cat class, Dog class, Dolphin class, etc). Some of the behaviour will be instance specific, they may have members like "weight", "name", "age", etc and have related getter/setter.
but then, there might be one method that would typically give the same result for all the instances of a given class, for example it could be one of those:
-int getNumberOfLegs();
-String getFavouriteFood();
All cats have 4 legs so that method could be static, it's not instance-dependant. it's more like meta information. I want to be able to do Cat.getNumberOfLegs(). I want to force the existence of that method on all my hierarchy in a way that can be overridden, etc.