Part 6 of 7 · 2 min read
The patterns left out
What else GoF contains.
The patterns left out
GoF has 23 patterns. This course covers sixteen of them in depth, plus the simple factory and injection, which are idioms and not GoF patterns. The others come up less often in design rounds. Each is listed here with its purpose, so the name does not surprise you.
| Pattern | Purpose (from GoF) |
|---|---|
| Bridge | Separate an abstraction from its implementation so both can vary |
| Flyweight | Share many small objects efficiently |
| Proxy | Stand in for another object, to control access to it |
| Mediator | Keep objects from referring to each other by routing talk through one object |
| Memento | Save and restore an object's state without breaking encapsulation |
| Visitor | Add new operations to a set of classes without changing them |
| Interpreter | Represent a grammar and an interpreter for sentences in it |
Proxy is close to Decorator in shape (it wraps an object with the same interface) and is worth a short read. Memento pairs with Command for undo. Visitor suits trees with many operations, such as a compiler.
If asked about one of these in a round, say what it is for, give a small example, and say how it differs from a nearby pattern. That is usually enough.
Common mistake
Naming patterns to sound clever. A design that works and is simple beats a design with six patterns that nobody needs. Name a pattern only when it solves a stated problem.
Interview angle
Answer in your head first, then open it.
How do you decide which pattern to use?
Start from the problem and ask what varies. Then check the intent and the cost of the pattern, and prefer the simplest design that works.
How do you tell Strategy from State?
The client chooses a strategy and it rarely changes. A state changes by itself as the object moves through its life.
Have you used several patterns together?
Yes, for example observer for events, an adapter at the edge, a decorator for logging, and a strategy for wording.
Check yourself: 1. Which unlisted pattern is closest in shape to Decorator? 2. Which pattern pairs with Command for undo?
Words you will meet
| Word | Meaning |
|---|---|
| Design pattern | A named, reusable solution to a repeating design problem |
| Intent | The reason a pattern exists, in one sentence |
| Consequence | What a pattern costs or limits |
| Look-alike | Patterns with the same shape but different aims |
| Over-engineering | Using more structure than the problem needs |