public interface State{ public void des(); public void action(); } public class State1 implements State{ Sys sys; public Sate1(Sys s) { this.sys=sys; } public void des(){ .../ implements } public void action(){ .../ change the state sys.setState(s.getState2()); } } public class State2 implements State{ Sys sys; public Sate2(Sys s) { this.sys=sys; } public void des(){ .../ implements } public void action(){ .../ change the state sys.setState(s.getState1()); } } public class Sys { private State1 state1; private State2 state2; private State state;//record the system's state ....//state1 & state2's setter & getter public Sys(State state) { this.state=state; } public void setState(State state) { this.state=state; } public void aciton() { state.action(); } }