Origin: |
GoF 95 |
Reason: |
To allow an object to dynamically change a set of attributes.
To change the nature (as opposed to the value) of an object's state.
|
Synopsis: |
Encapsulate the state of one object as one of a set of objects
with the same superclass.
|
Example: |
A dialog box in a GUI may have different buttons at different times.
The behavior of a same button may radically change over time.
|
Solution: |
Context |
Class whose instances exhibit stateful behavior.
It keeps a reference to a ConcreteState object
that implements the state functionality.
It is the client of the State pattern.
|
ContextState |
Superclass of all classes used by Context
to represent a state. It provides methods for
state initialization and change.
|
ConcreteStatei |
Concrete subclass of ContextState.
It is referenced by Context.
|
|
See also: |
Delegation
(the state functionality of an object is delegated to another object)
Flyweight and
Singleton
(to implement shared or unique-instance states)
|