Which pattern, when
medium 45 minA pattern is an answer to one kind of pressure.
Watch lesson4:38
Check yourself
One question at a time. Each answer explains why.
Question 1 of 12
What comes first?
Adults pay 10, children 5, seniors 7. Which answer fits?
An editor needs undo. Which pattern answers this force?
What separates Decorator from Proxy?
A delivery may be cancelled only before it leaves. Nothing else changes by phase. Best first choice?
The word different in a prompt means
A hotel system runs in one hotel. Should Hotel be a Singleton?
A library offers `sendMsg(bytes)`, your code calls `notify(text)`. Which pattern?
In the logger row, why a chain or a list of handlers?
Which follow-up shows that Observer is needed?
Your Strategy interface has had one class for two years. What now?
Why should a listener be called after the change?
Pick an answer to see why.
Not quite. Without a force there is nothing for a pattern to answer.
Not quite. Only a number differs.
Not quite. The action must outlive its call.
Not quite. The drawing is the same.
Not quite. Phases only limit moves, so data is enough.
Not quite. Formulas, classes or only numbers may differ.
Not quite. One is enough is not the same as a second would be wrong.
Not quite. Useful class, wrong interface.
Not quite. The handlers vary and have an order.
Not quite. An open list is the force.
Not quite. The force did not come.
Not quite. Otherwise people hear about something that did not happen.
Flashcards
Say your answer, then reveal it.
Card 1 of 13
What is a force?
The pressure that makes the simple version hurt, for example a rule that keeps changing.
Say your answer, then reveal it.
Order of the four parts?
Force, pattern, cost, exit.
Say your answer, then reveal it.
Cheap answer before Strategy?
A function parameter, or a table if only numbers differ.
Say your answer, then reveal it.
Cheap answer before State?
An enum and a table of allowed moves.
Say your answer, then reveal it.
Strategy or State in one question?
Who changes it: somebody outside, or the object itself?
Say your answer, then reveal it.
Adapter, Decorator, Proxy?
Translate, add, control.
Say your answer, then reveal it.
Keywords for Command?
Undo, redo, history, queue, execute, action. Then ask: must the action be kept?
Say your answer, then reveal it.
When is Singleton justified?
When a second instance would break something real in the process.
Say your answer, then reveal it.
Patterns in the elevator row?
State for doors and motion, Strategy for which car answers.
Say your answer, then reveal it.
Why not a read-write lock for an LRU cache?
A read also moves the entry, so it writes.
Say your answer, then reveal it.
How many classic patterns, in which groups?
23: five creational, seven structural, eleven behavioural.
Say your answer, then reveal it.
Two patterns in one design: rule?
One per force, each in its own class, removable alone.
Say your answer, then reveal it.
Where do notifications go?
After the change is complete, each listener guarded on its own.
Say your answer, then reveal it.
These cards come back in Today, just before you would forget them.