Gof State

State in modern Java: making an object's behaviour depend on an explicit state, with the transitions themselves modelled rather than implied by scattered flags. Covers the intent difference from Strategy, where transitions should live — in the state classes, in a table, or in one exhaustive switch — sealed records against enums, rejecting illegal transitions by default, persisting a state through stable codes rather than ordinals, atomic transitions under concurrency, and timeouts as transitions in a durable workflow. Use when boolean flags multiply on an entity, when a status field is checked in scattered ifs, when an illegal transition reaches production, when a workflow must survive a restart, or when two requests transition the same entity concurrently. Does not cover interchangeable algorithms chosen by a caller (gof-strategy), saga orchestration across services (distributed-transactions-and-sagas, gof-mediator), or optimistic locking mechanics (offline-concurrency-control).

robsonkades Updated

File contents

robsonkades/agent-skills/tree/main/skills/gof-state commit 6f07bd468c

Frequently asked questions

npx skillmds@latest add robsonkades/gof-state