Design Patterns
Creational, structural and behavioral patterns and when to reach for them.
21 notes · 131 min total
In the interview
You won't have time to implement a pattern in full. Name the pattern that fits the scenario, say why in a sentence, and move on. Study the patterns to understand why they exist and what problem each one solves. You don't need to memorize the templates.
Right before an interview
Brush up on the Pattern Reference Cards and Choosing the Right Pattern, at the bottom of this list.
- 1What Are Design Patterns?What design patterns are, why they matter, and how the creational, structural and behavioral families differ.7 min
- 2How to Read a Design PatternThe standard sections of a pattern description, which ones to read first, and a worked Observer example.4 min
- 3The Gang of Four (GoF)Who the Gang of Four were, the 23 patterns they cataloged, and which ones you'll meet in modern code.5 min
- 4Factory Method PatternMove object creation out of business logic with a Simple Factory, a registry, or the GoF Factory Method, and know when each fits.8 min
- 5Abstract Factory PatternCreate whole families of related objects through one factory so incompatible pieces can't be mixed.4 min
- 6Builder PatternBuild complex, often immutable objects step by step with a fluent builder or a director, instead of long constructors.7 min
- 7Prototype PatternCreate new objects by cloning a configured prototype, and understand why shallow copies are dangerous.5 min
- 8Singleton PatternGuarantee one instance with thread-safe Python singletons, how they break, and why dependency injection is often better.8 min
- 9Adapter PatternWrap a legacy class or third-party SDK so it fits the interface your code expects, without changing either side.8 min
- 10Bridge PatternSplit two independently varying dimensions into separate hierarchies joined by composition, turning N × M subclasses into N + M.5 min
- 11Composite PatternBuild tree structures where single items and groups share one interface, so client code treats them the same.5 min
- 12Decorator PatternStack optional behavior onto an object at runtime by wrapping it in objects that share its interface.6 min
- 13Facade PatternHide a complicated subsystem behind one simple class that runs common workflows in the right order.7 min
- 14Flyweight PatternSave memory across huge numbers of similar objects by sharing their common, immutable state through a caching factory.8 min
- 15Strategy PatternReplace if/else chains of algorithms with interchangeable strategy objects that a context can swap at runtime.7 min
- 16Observer PatternLet one subject notify any number of subscribers when its state changes, without knowing who they are.6 min
- 17Command PatternTurn requests into objects so you can queue, log, combine and undo them, and decouple buttons from the work they trigger.7 min
- 18State PatternModel state machines like vending machines and document workflows with one class per state instead of if/else on a state field.7 min
- 19Template Method PatternFix an algorithm's sequence of steps in a base class and let subclasses fill in only the steps that vary.6 min
- 20Choosing the Right PatternQuestions and keyword cues that tell you which pattern family, and which pattern, fits the problem in front of you.3 min
- 21Pattern Reference CardsOne-page GoF-style cards for seven core patterns: intent, problem, structure, when to use, trade-offs and known uses.8 min