State mode, which is mainly used for operations where there is a large number of case judgments, and the case depends on the state of the object, it is possible to encapsulate a large number of case judgments as separate classes.
Context:
-state the current state object.
Changestate (state), toggles the state object.
Operationinterface (), call State->operationinterface.
Operationchangestate (), call State->operationchangestate (Context).
State:
Changestate (context,state), called Context->changestate (state).
Operationinterface (), virtual, subclass implementation.
Operationchangestate (Context), virtual, sub-class implementation.
Statea:
Operationchangestate (context), called base->changestate (context, specified state).
Operationinterface (), subclass specific operation implementation.
In Statea, operationchangestate, if the extension, the individual think can be passed as a parameter, so that the context of state switching, you can do dynamic state changes, rather than the specific state changes as above, Only the code is written in a to B.
Learning Notes-state mode