Choosing a Behavioural Pattern
Choosing a behavioural design pattern: telling Strategy, State, Template Method, Command, Observer, Mediator, Chain of Responsibility and Decorator apart by who decides and how many objects take part.
Several behavioural patterns share a class diagram, so the diagram alone rarely names the pattern. What does is a question about the code: who decides which behaviour runs, when the work runs, and how many objects take part. This topic gathers the pairs and groups most often confused, and the question that separates each.
It opens on Strategy, State and Template Method, with one shipping problem written all three ways so that only the decider changes. Command against Strategy follows, two objects with one method that differ in what the method stands for. Then two pairs that share a shape: Observer against Mediator, and Chain of Responsibility against Decorator, a structural pattern that is built the same way.
The exercise gives eight short descriptions to name, and the recap gathers the questions that decide them.
Contents
5 cardsnot started