State mode
allows an object to change its behavior when the internal state changes, and the object looks as if it had modified its class.
The roles involved in state mode are:
Environment (context) role , as well as context: defines the interface to which the client is interested, and preserves an instance of a specific State class. An instance of this specific State class gives the existing state of this environment object.
Abstract State Role : Defines an interface that encapsulates the behavior of a particular state of an environment (context) object.
specific status (concretestate) role : Each specific state class implements the behavior of a state of the environment (context).
Applicable scenarios:
1. The behavior of an object depends on its state, and it must change its behavior according to the state at run time.
2. An operation contains a large, multi-branched structure, and these branches are determined by the state of the object.
State mode of learning notes in design mode