State pattern comes under Behavioral design pattern.
It lets an object to change its behavior when its internal state changes.
Behaviour & Advantages
Supports state specific behavior.
Defines an object oriented state machine.
The state context hold a reference to current state.
Maintains a reference to current state which is initialized with an initial state.
It lets the clients change its state by exposing some API.
Abstract interface for defining state specific behavior.
An implementation of State specific behavior.
This examples shows a toggle switch. Here StateContext class
acts as State Context and IState interface acts as State.
SwitchOff and SwitchOn classes implement IState which acts as Concrete States.
StateContext is instantiated with an initial state SwitchOff.