Short question
As I know, most OOP languages do not enable to inherit static fields. (C++, Java, C#)
On the other hand, OOP says that you shouldn't duplicate code.
- Is there a common way in OOP languages, that makes something like "static field inheritance"?
- Do you know an easier, language-specific unique way to solve the problem?
- Are there languages which have that "integrated"? (I mean like a keyword.)
(Anyway, I know the basic intent of the static fields, I just want to go deeper and avoid any duplication.)
My concrete problem
I want to make a framework (C# or Java), and make it the easier way to expand. Therefore I want the constrains and informations about inherited classes to put in a base class as soon as possible.
I know, that each inherited class must have an own static field. (I want to make an object counter per subclass.)
Therefore it seems logical to make something like "static field inheritance" - where the static field is needed for the subclasses, not for the base class.
I've seen some tricky solutions (for example: in C#, used generics in C# abstract class static field inheritance) , but i can't believe there is no easier way.
If there is no easier way, please explain me how should I find out to use generics?
How should I look on generics in this context? What kinds of problems should i associate with them?
(In school we learned it only "to avoid code duplicating", the static field detachment was not emphasizing! It seems to me in this context, that generics are classes and instanties at the same time, but i have not found any understandable, logic approach for that yet.)