Let's imagine that I have two classes Person1 and Person2, which implements the interface History. I want to have a static method inside History interface that return Person1 or Person2 depending on a string like this :
public static Object getPerson(String p){
switch(p){
case "a":
return new Person1();
default:
return new Person2();
}
}
I don't have any error here. But how to use it in another class, in order to get methods from Person1 or Person2 ? I tried to do this :
Object env = IEnvironment.getPerson(clientEnv);
But I can't write env.myMethod() for example.
Is an interface the right solution ? How to achieve this ? Thanks!