[Previous] [Next]
Here are the roles and functions of the State design pattern:
- State Specifies an interface expected by clients that encapsulates the behavior of a concrete State class instance. This interface is referred to as State because concrete classes that implement this interface are expected to be sensitive to state changes.
- ConcreteState subclasses Each subclass implements behavior associated with a specific state. The subclass doesn't maintain its state in local data-member variables. Instead it defers state management to the CentralStateManager object.
- CentralStateManager A concrete class that performs the following actions:
- Serves as the single central repository for all state objects within a State design pattern instance. State is determined based on the values of data member variables.
- Defines intelligent state transition behavior by returning a reference to the appropriate ConcreteState object based on the current state. This results in dynamic behavior changes.