The status mode is for system state conversion. Its main definition is as follows:
State mode: allows an object to change its behavior when its internal state changes. The object seems to have modified its class.
To facilitate State transfer, we define a common interface for the State, and then implement this interface for each State. In the system class, the system itself is passed into the state class through the constructor, in this way, each state change can be completed within its own class, while improving Scalability:
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(); }}
Although the implementation status mode is similar to the policy mode and the template method, several design modes are completely different. The policy mode encapsulates interchangeable behaviors, then, the delegate method is used to determine which behavior to use. The template method is determined by the subclass to determine how to implement certain steps in the algorithm, and the algorithm flow is given, the State mode encapsulates state-based behaviors and delegates the behaviors to the current state, which determines the specific behaviors.
Design Mode-status Mode