The state design pattern is used to encapsulate the behavior of an object depending on its state. The state implementation reflects the behavior the o

The Super State Design Pattern

submited by
Style Pass
2021-05-26 11:00:08

The state design pattern is used to encapsulate the behavior of an object depending on its state. The state implementation reflects the behavior the object should have when being in that state.

A finite state machine describes a computational machine that is in exactly one state at any given time. It can change from one to another state in response to some input / trigger / event.

The emphasis of the state design pattern is on encapsulation of behavior to create reusable, maintainable components (the states). The focus of the finite state machine is on states and their transitions (captured by the state diagram) but not on the actual behavior (that’s an implementation detail).

This article describes how these two concepts can be combined by using a finite state machine to describe and manage the states and their transitions for an object that delegates behavior to state objects using the state design pattern.

The state design pattern is one of twenty-three design patterns documented by the Gang of Four. It’s a strategy pattern set to solve these two main problems:

Leave a Comment