The State Pattern is a Software Design Pattern like the Observer Pattern that I used during my year in industry in 2020. It is used to implement state specific behaviour, and to control allowed transitions between states.

It is comprised of three parts

  1. The Context maintains a reference to a concrete state.
  2. The State Interface allows the context to communicate with concrete states. Only the context may communicate with states.
  3. The Concrete States are the objects for each state with contain the state-specific methods.