bigonotes
CS ConceptsDesign Patterns

Design Patterns

Creational, structural and behavioral patterns and when to reach for them.

21 notes · 120 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 — there's no 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.

Pattern Reference Cards →Choosing the Right Pattern →

  1. 1What Are Design Patterns?What design patterns are, why they matter, and how the creational, structural and behavioral families differ.6 min
  2. 2How to Read a Design PatternThe standard sections of a pattern description, which ones to read first, and a worked Observer example.4 min
  3. 3The Gang of Four (GoF)Who the Gang of Four were, the 23 patterns they catalogued, and which ones you'll actually meet in modern code.4 min
  4. 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.7 min
  5. 5Abstract Factory PatternCreate whole families of related objects through one factory so incompatible pieces can't be mixed.4 min
  6. 6Builder PatternBuild complex, often immutable objects step by step with a fluent builder or a director, instead of long constructors.7 min
  7. 7Prototype PatternCreate new objects by cloning a configured prototype, and understand why shallow copies are dangerous.5 min
  8. 8Singleton PatternGuarantee one instance with thread-safe Python singletons, how they break, and why dependency injection is often better.8 min
  9. 9Adapter PatternWrap a legacy class or third-party SDK so it fits the interface your code expects, without changing either side.7 min
  10. 10Bridge PatternSplit two independently varying dimensions into separate hierarchies joined by composition, turning N × M subclasses into N + M.4 min
  11. 11Composite PatternBuild tree structures where single items and groups share one interface, so client code treats them the same.4 min
  12. 12Decorator PatternStack optional behavior onto an object at runtime by wrapping it in objects that share its interface.6 min
  13. 13Facade PatternHide a complicated subsystem behind one simple class that runs common workflows in the right order.6 min
  14. 14Flyweight PatternSave memory across huge numbers of similar objects by sharing their common, immutable state through a caching factory.7 min
  15. 15Strategy PatternReplace if/else chains of algorithms with interchangeable strategy objects that a context can swap at runtime.6 min
  16. 16Observer PatternLet one subject notify any number of subscribers when its state changes, without knowing who they are.5 min
  17. 17Command PatternTurn requests into objects so you can queue, log, combine and undo them, and decouple buttons from the work they trigger.6 min
  18. 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
  19. 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
  20. 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
  21. 21Pattern Reference CardsOne-page GoF-style cards for seven core patterns: intent, problem, structure, when to use, trade-offs and known uses.8 min