I want each class that implements an interface to have a static factory method, as defined by the interface. I.e:
public interface Handle {
public static Handle GetHandle() {
return null;
}
public void DoThings();
}
public class HandleA implements Handle {
private HandleA();
public static HandleA GetHandle() {
return new HandleA();
}
public void DoThings() {
return;
}
}
// This is allowed even though HandleB doesn't provide a GetHandle()
public class HandleB implements Handle {
private HandleB();
public void DoThings() {
return;
}
}
Reading past questions, it seems like the static method GetHandle() isn't enforced in concrete classes of Handle because that's not what the intended design behavior of static interface method is. Is there another way to do what I want? (i.e enforce all implementations of Handle to provide a "factory" GetHandle() method).