IT lexicon › Programming › State pattern

State pattern

Programming På svenska → Updated: 2026-10-25

An object changes its behaviour when its internal state changes, appearing to switch class at runtime.

Another Gang of Four pattern (1994) that game programmers made their own. A character that can stand, run and jump models neatly as one state per class, each with handleInput(), update() and transitions to other states. It is an object-oriented way to build a finite state machine without a swelling switch statement.

The upside is that each state encapsulates its own logic; the downside is that an explosion of states quickly becomes hard to follow, which is why larger games often move on to hierarchical state machines or behaviour trees.

← Back to the lexicon