Alias: Objects for States, Envelope-Letter.
How to treat an object whose behavior is strongly dependent on its internal state, without checking this state at each operation call?
The object behavior depends on its state.
Operations have large, multipart conditional statements that depend on the object’s state.
State-specific behavior is isolated, increasing maintainability.
Replacing a conditional by a delegation may reduce performance.
State transition become explicit, increasing testability.
The Context: less robust
The States: the context must provide an appropriate interface and the states must know the context.
When the context is created.
Later (lazy instantiation).
Dynamic inheritance may be used in Self
State sub-instances may be shared by several contexts, if they do not contain properties.
The State pattern is part of the GoF Catalog.
It was applied to TCP connection protocols [Johnson and Zweig 91] and to graphical editors such as HotDraw [Johnson 92] and Unidraw [Vlissides and Linton 90].