In the state pattern, a class behavior changes based on its state. This type of design pattern comes under the behavior pattern.
In the state pattern, we create objects that represent various states and a context object whose behavior varies as its state object changes.
The role of this pattern is to adapt its behavior depending on the internal state of an object. It can be used when implementing the dependency of the state object if the condition statement becomes complex.
The generic class diagram structure of the state pattern is as follows:
The participants in the state pattern are as follows: