I'm a Java/C#/PHP developer, through my OOP programming experience I find myself asking the same question: Why static members can't be abstract and don't implement polymorphism especially in situations involving factory methods, for example:
abstract class Resource {
public void doSomething();
}
abstract class User<resource extends Resource> {
//if i want to instantiate resource,
//my only option here is to create an abstract factory in user class
protected abstract resource create();
public void use(){
create().doSomething();
}
}
class FileUser extends User<File> {
//It's a bit clumsy, isn't it?
@Override
protected Internet create() {
return new File();
}
}
when abstract static methods would get me rid of these abstract factories: (Below is not a valid code)
abstract class Resource {
public void doSomething();
//Im not sure how the child class would get passed though
static abstract Resource create();
}
abstract class User<resource extends Resource> {
public void use(){
resource.create().doSomething();
}
}
So, does anyone know why this kind of behavior wouldn't be approved in OOP? Sorry if it sounds like a silly question.