Skip to content

State Machine

Stable ID: pattern.state-machine
Kind: design-pattern
Status: stable
Source: skill/references/design-patterns/state-machine.md

Purpose

Model allowed states, events, guards, and transitions explicitly when lifecycle behaviour is non-trivial.

Use when

  • Illegal transitions must be prevented and explained.
  • Concurrent or long-lived workflows have observable lifecycle states.

Avoid when

  • There are only two obvious states with no transition rules.
  • A large framework obscures a small enum and match statement.

Applicability

  • Languages: any, python, q-kdbplus, cpp, rust, dart-flutter, typescript
  • Related entries: example.explicit-state-machine, pattern.command