definition : Allows an object to change its behavior when its internal state changes. The object appears to have modified its class.
Nature : Separates and chooses behavior according to state.
State : The property value of the object instance.
behavior : The function of an object is mostly mapped to a method.
the function of State mode : The behavior of separating state, by maintaining the change of state, to invoke different functions corresponding to different states.
States and behaviors are associated and can be described as: state-determined behavior .
(1) Defining State enumerations
public enum Magicstate {lock,download, downloading, PROCESS, processing, sound};
(2) Setting status
public void SetState (Magicstate state) {this.state = state};
(3) Adding a method to a state
private void Switchmagicstate (Magicstate ms) {LOGGING.D (TAG, "switchmagicstate|ms =" + ms); mmagictask.state = Ms;switch ( MS) {case LOCK: //.......lock related methods break;case download:break;case downloading:break;case process:break;case Processing:break;case Sound:break;default:break;}}
(4) Toggle Status
State management of Java design patterns