So I have a few different implementations of State (StateImplementation and OtherStateImplementation)
And I need to return a new implementation if a certain event happens. The method can return N amount of different implementations.
public class State() {
// Contains various methods
}
public class StateImplementation extends State {
public State onEvent(String event){
if(event.equals("foo")){
return new OtherStateImplementation();
} else {
return this;
}
}
}
public class OtherStateImplementation extends State {
// Second implementation
}
How would I go about doing this, as the types don't match the return type if I do it like this.