Intent
- Allow an object to adjust its behavior based on its state
Structure

Clientdoes not need to know about theObjectstates as well as the associations between the states and the object behaviors.- The behaviors are now handled by the corresponding
Stateobjects. - The state transition method can be centralized in the
Objector distributed over the concrete states. - The
Objectcan also pass itself as an argument to the operations ofStateobjects. This helps the state objects to access the information in theObject.
Applicable contexts
- You want to modify the object’s behavior at run-time depending on its state.
- You want to eliminate the duplications of the conditional clause on the object’s states currently scatterring over different places.
- You want to emphasize the transitions between states.
- You want to emphasize the associations between states and behaviors.
- There are complicated logics revolving around the object states, and each of those states can transform to another state.
Risks
- Increase the number of classes, as each state is now a class itself
- Increase the number of objects, but this risk can be reduced by reusing the same instance of the state (if possible)
- More complicated code
Example
References
[1] State, The GOF book