I have an abstract class type that I'm inheriting from to create new classes. As an equivalent example, consider:
public abstract class BaseClass {
public BaseClass(String input)
{
...
}
public abstract void doSomething();
public String getResult()
{
...
}
}
Now I can override BaseClass and implement "doSomething" to perform different actions (for example, reverse or capitalize, if I were really working with strings, though I'm not really, it's just an example).
The most common usage is:
BaseClass bc = new ExtendsBaseClass(input);
bc.doSomething();
String result = bc.getResult()
So I want to make a static wrapper method for this.
I'd like to implement:
public static String doSomethingForResult(String input)
{
BaseClass bc = /*new current type*/;
bc.doSomething();
return bc.getResult();
}
But I have no idea what to replace that comment with, or how to make it work; I don't want to force every implementing class to re-implement this (if that's even conceptually possible; since abstract static is not allowed.
BaseClass bc = BCFactory.getDefaultInstance();. But you should not use that static method.