How to learn design patterns

What patterns are, the three families, a map of the classic catalogue, and a practical way to learn them without over-engineering.

On the roadmap:Software Design · step 1: Design principles

Lesson 1 of 7 · 9 min read · quiz · exercise

What a pattern is

A design pattern is a named solution to a recurring design problem, together with when it applies and what it costs. The famous catalogue, Design Patterns (1994) by Gamma, Helm, Johnson and Vlissides ("the Gang of Four"), described 23 patterns in object-oriented software.

Patterns give you three things:

  1. A shared vocabulary: "use a factory here" communicates a whole idea in a few words.
  2. Proven structures you do not have to invent under pressure.
  3. Awareness of trade-offs, since each pattern comes with consequences.

They are not copy-paste code, and not a goal in themselves.

The three families

Figure SDA-SDE-01-1 · The three families · © forcsguy.com

The catalogue at a glance

PatternOne-line ideaTypical use
Factory MethodA method decides which concrete class to createCreate objects without hard-coding the class
Abstract FactoryCreate families of related objectsThemes, platform-specific widget sets
BuilderBuild a complex object step by stepObjects with many optional parts
PrototypeCreate objects by copying an existing oneCostly-to-create objects
SingletonExactly one instance, globally reachableRare; often better as dependency injection
AdapterMake one interface look like anotherWrap a third-party library
BridgeSeparate an abstraction from its implementationSeveral dimensions of variation
CompositeTreat a tree of objects like a single objectFile systems, UI trees
DecoratorAdd behaviour by wrapping an objectLogging, caching, compression layers
FacadeA simple front for a complex subsystemA clean API over messy internals
FlyweightShare common state to save memoryMany similar small objects
ProxyA stand-in that controls accessLazy loading, access control, remote calls
StrategySwap algorithms behind an interfacePricing rules, sorting choices
ObserverNotify dependants when something changesEvents, UI updates
CommandTurn a request into an objectUndo, queues, macros
StateBehaviour changes with internal stateWorkflows, connections
Template MethodA skeleton algorithm with customisable stepsFrameworks, hooks
IteratorWalk a collection without exposing its structureLoops over any collection
Chain of ResponsibilityPass a request along handlers until one handles itMiddleware, validation chains
MediatorOne object coordinates othersChat rooms, form logic
MementoSave and restore an object's stateUndo, snapshots
VisitorAdd operations to a structure without changing itCompilers, reports over trees
InterpreterEvaluate sentences of a small languageRules, expressions

The next lessons explain the most useful ones with examples.

A practical way to learn

  1. Learn the problems first. Each pattern exists because of a pain: rigid code, duplicated code, tangled dependencies. Understand the pain, then the cure.
  2. Start with the ones you already use without naming them: Iterator (every for...of), Observer (event listeners), Decorator and Chain of Responsibility (middleware), Strategy (a function you pass in).
  3. Implement each once, small, in your language, and write what you gave up.
  4. Spot them in real code: frameworks and standard libraries are full of patterns.
  5. Refactor towards a pattern when the code hurts, rather than starting with one.

Patterns look different in different languages

In languages with first-class functions, several patterns shrink to a function: Strategy is a function argument, Command is a closure, Observer is a callback list, and Template Method is passing the varying step. In dynamic languages, Factory and Adapter are often trivial. Learn the intent, then use the lightest form your language allows.

Anti-patterns to avoid

  • Pattern overload: five layers of abstraction for a feature that needs ten lines.
  • Singleton as global state: hides dependencies and makes testing hard.
  • Naming something by the pattern, not by what it does (ManagerFactoryProvider).
  • Applying a pattern "in case": wait until the second or third time you need the flexibility.

Real-world reading

Check your understanding

Question 1 of 3

0 correct so far

What is a design pattern?

Go deeper

  • Refactoring Guru: design patterns by Refactoring Guru: free catalogue with examples in several languages
  • Head First Design Patterns by Freeman and Robson: a beginner-friendly, example-led introduction to the same catalogue

© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.