Card 05/ 05
Recap: Choosing a Behavioural Pattern
Ask who decides, when it runs, and how many objects take part.
The behavioural patterns most often confused are told apart by a few questions about the code.
- Who decides the behaviour? The caller, by passing an object in, is Strategy; the object itself, switching as it runs, is State; a subclass, when it is written, is Template Method.
- Is it a request or an algorithm? A request to keep, queue or undo is Command; a way of doing a job now is Strategy.
- Does one object decide for the others? Yes is Mediator; each listener deciding for itself is Observer.
- Can an object in the line stop the call? Yes, and one handles it, is Chain of Responsibility; every object passing it on, adding a layer, is Decorator.
← → move through sections and cards