05 Specialist patterns and concepts
Specialist patterns and concepts
Use the concrete problem before the pattern name
These fifteen topics are additional tools, not a checklist of classes that every program needs. Unlike the earlier discovery section, a specialist exercise may tell you the conventional name first. You still need to decide which behavior the caller expects and whether the named tool is justified.
A first example is copying nested state. If original = {'tags': ['a']}, a shallow copy can still share its inner list. Changing the copy then unexpectedly changes the original. A deeper copy duplicates the nested mutable list so one owner can edit its copy independently. The test for Prototype demonstrates the difference rather than requiring a pattern-shaped class.
Three more concrete mental models:
- Immutable value: two
Money(100, "USD")objects represent the same amount even though they are separate objects. Adding another amount returns a new Money object rather than editing the original; mismatched currencies cannot simply be combined. - Builder snapshot: call
builder.url("/a").build()and keep that request. If the builder later changes to"/b", the first built request must still refer to"/a". - Event history and replay: start from zero, append facts
(+3, -1), and compute two. Replaying the same saved facts into a fresh aggregate should produce two again without changing the stored history. This is different from storing only the latest number.
For every following topic, ask: What practical failure would occur without this mechanism? What must stay shared, and what must remain separate? Is there a simpler way with the same behavior? Try to answer those questions before reading the full reference hint. Earlier concepts like interfaces, ownership and the order of calls still apply, but a new pattern name is never itself a reason to add complexity.
These concepts are taught around the concrete problem they solve. Use SCOAT where it helps, but do not force every checkpoint to produce structure. Specialist/revision units may name the concept up front; the executable property remains more important than vocabulary.
Loading sign-in options…