System Design
15. Software Design PatternsAnimated walkthrough
State Pattern
Change behaviour when the state changes.
The idea
An object delegates to a state object that implements the current behaviour.
Watch it work
The steps light up one at a time. Use the controls to pause or step through.
- 1Define state classes
- 2Context holds the current state
- 3Actions delegate to it
- 4States trigger transitions
1/4
Step by step
- 1Define state classes
- 2Context holds the current state
- 3Actions delegate to it
- 4States trigger transitions
Where it is used
Workflows and state machines.
Watch out for
Many classes for simple machines.