Free Design patterns lessonsDesign patterns · Stage 2 · Behaviour and communication · Step 3
State
Letting an object change how it behaves as its state changes, by moving each state's behaviour into its own class. About 12 minutes.
What is the key difference between the state pattern and the strategy pattern?
- AIn state, the states themselves cause the transitions: the object changes its own behaviour over time
- BState has no interface
- CState uses static methods
Show the answer
In state, the states themselves cause the transitions: the object changes its own behaviour over time. In strategy the client picks and swaps the algorithm.
4 questions on this idea
Short questions that apply the idea to new cases: trace it, work out a number, put steps in order. A wrong answer explains itself.
Answer them in your browserFree account, no card. Your progress is saved, and the idea comes back in a quick review later.
Sign up free to solve