gof-state
Installation
SKILL.md
One-line summary
Allow an object to alter its behavior when its internal state changes — making the object appear to change its class. Each state is encapsulated in its own class; the context delegates behavior to whichever state it currently holds.
When to use this skill
- An object has multiple, well-defined states and its behavior depends meaningfully on which state it is in (gumball machine, order lifecycle, network connection, parser).
- The current implementation has a large
switchorif-elseover a status enum where each branch does substantially different work. - The set of states is bounded and known; transitions between them are limited and rule-bound.
When NOT to use this skill
- Only two states with trivially different behavior — a single boolean flag and a small
ifis simpler. - The "state" is actually data, not behavior — that's a value object, not a state machine.
- The states are not mutually exclusive (multiple flags can be true simultaneously) — that's not a state machine; it's a feature flag matrix.
Core content
The pattern has three parts: