public class State{
private String value;
public void setValue(){
this.value = value;
}
public String getValue(){
return value;
}
public void method1(){
System.out.println("this is first opt1");
}
public void method2(){
System.out.println("this is second opt2");
}
}
public class Context{
private State state;
public Context(State state){
this.state = state;
}
public void setState(State state){
this.state = state;
}
public State getState(){
return state;
}
public void method(){
if(state.getValue().equals("state1"))
state.method1();
}
if(state.getValue().equals("state2"))
state.method2();
}
}
public class Test{
public static void main(String args[]){
State state = new State();
Context context = new Context(state);
state.setValue("state1");
context.method();
state.setValue("state2");
context.method();
}
}