At the top of my class hierarchy is the class Mammal
. Each instance of Mammal
is required to statically initialize itself. (The example is silly, I know. If you are curious, I am using Android fragments and I cannot override their constructors)
For example:
public abstract class Mammal{
private static initialize(int a, String b, ...){
...
}
}
public class Dog extends Mammal{
public static Dog newInstance(int a, String b, ...){
Dog dog = new Dog();
initialize(a, b, ...);
}
}
public class Cat extends Mammal{
public static Cat newInstance(int a, String b, ...){
Cat cat = new Cat();
initialize(a, b, ...);
return cat;
}
}
The classes could continue indefinitely. I have looked into calling a subclass constructor from a superclass but I cannot figure out how to apply it to a static context. Thanks in advance!