I am trying to create a static method that would return an instance of the class, something like:
class A {
public static A getInstance() {
return new A();
}
}
The problem I am having is that if I have a subclass B derived from A, I would like B.getInstance() to return an instance of B, and not A. In PHP world, you could use a keyword "self" to reference to your own type, so your getInstance() would look like:
public static function getInstance() {
return new self();
}
What's the best way to go about this?