bigonotes
CS ConceptsDesign Patterns

How to Read a Design Pattern

The standard sections of a pattern description, which ones to read first, and a worked Observer example.

4 min readLast updated

Recipes all share a format: ingredients, prep time, steps, serving suggestions. Design patterns are documented the same way. Once you know the template, you can pick up any pattern from a book or website and know where to look for what you need. This note walks through that template and fills it in for one pattern.

The anatomy of a pattern description#

Every pattern description, however long, answers three questions:

Part Question it answers
Problem What pain does it solve?
Solution What's the blueprint?
Consequences What are the trade-offs?

Read the problem first. Without it, patterns feel like solutions looking for problems.

Those three parts are the minimum. The Gang of Four book expands them into a fuller template, and most pattern sites still follow it:

Section What it tells you
Name The handle you use in conversation ("let's use a Singleton")
Classification Creational, Structural or Behavioral
Intent One or two sentences: what the pattern does (its elevator pitch)
Also known as Other names for the same idea
Motivation A concrete scenario showing the problem
Applicability Situations where the pattern fits
Structure A class diagram of the participants
Participants / Collaborations Each class's role and how they work together
Consequences Benefits, costs and trade-offs
Implementation / Sample code Tips, pitfalls and code
Known uses Real systems that use it
Related patterns Similar or complementary patterns

Worked example: Observer#

A template is easier to understand once you see it filled in. Here it is for Observer, one of the most common patterns.

Classification: Behavioral.

Intent: Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

Also known as: Publish-Subscribe, Dependents, event listener.

Motivation. A weather station collects temperature and humidity. Several displays need the data: current conditions, statistics, forecast, a mobile app. The naive design has the station call each one:

weather_station.update_current_display()
weather_station.update_stats_display()
weather_station.update_forecast()
weather_station.update_mobile_app()

The station now knows every display (tight coupling), adding a display means editing the station, and you can't add or remove displays at runtime.

Observer fixes this by flipping the relationship: displays sign up with the station instead of the station knowing about them.

Structure. The station holds a list of observers and calls update() on each one; every display implements the same interface.

Observer structure: WeatherStation holds a list of Observers and notifies them; CurrentDisplay, StatsDisplay and MobileApp implement the Observer interface

Applicability. Use Observer when:

  • A change to one object requires changing others.
  • You don't know in advance how many objects need to react.
  • An object should notify others without knowing who they are.

Real-world examples: newsletter subscriptions, YouTube subscribers, stock price alerts, GUI event handling.

Consequences.

Pros Cons
Loose coupling between subject and observers Notification order is not something you should rely on
Observers can be added or removed at runtime Forgotten observers cause memory leaks
Subject doesn't know concrete observer classes Cascading updates can be hard to debug
Supports broadcast communication Many observers means slower notifications

Implementation. Here is the subject side in Python. Each display would subclass Observer and implement update().

from abc import ABC, abstractmethod


class Observer(ABC):
    @abstractmethod
    def update(self, temp: float, humidity: float) -> None: ...


class Subject(ABC):
    @abstractmethod
    def subscribe(self, o: Observer) -> None: ...

    @abstractmethod
    def unsubscribe(self, o: Observer) -> None: ...

    @abstractmethod
    def notify_all(self) -> None: ...


class WeatherStation(Subject):
    def __init__(self) -> None:
        self._observers: list[Observer] = []
        self._temperature = 0.0
        self._humidity = 0.0

    def subscribe(self, o: Observer) -> None:
        self._observers.append(o)

    def unsubscribe(self, o: Observer) -> None:
        self._observers.remove(o)

    def set_measurements(self, t: float, h: float) -> None:
        self._temperature = t
        self._humidity = h
        self.notify_all()  # every state change triggers a broadcast

    def notify_all(self) -> None:
        for o in self._observers:
            o.update(self._temperature, self._humidity)

Known uses. GUI toolkits' event callbacks (Tkinter's bind), Python's logging handlers, JavaScript EventEmitter and DOM events, .NET events and delegates, the model-notifies-views part of MVC.

Related patterns. Mediator centralizes complex communication; an event bus is a centralized variant of Observer.

Which sections to read, and when#

You won't read every section every time. Which ones matter most depends on why you're reading.

You are... Read first
Learning a pattern Intent → Motivation → Structure → Implementation
Evaluating whether it fits Applicability → Consequences → Known uses
Implementing it Implementation → Consequences (what to watch out for) → Related patterns

What to learn first#

Once you can read a pattern description, the next question is which patterns to read. You don't need all 23 at once. Learn them in roughly this order:

Tier Patterns
Essential Singleton, Factory Method, Observer, Strategy, Decorator
Very useful Adapter, Builder, Command, Facade, Iterator
Good to know Template Method, State, Proxy, Composite, Abstract Factory

Key takeaways#

  • Every pattern description answers: what problem, what solution, what trade-offs.
  • The intent is the one-line summary; the motivation is the problem in context.
  • Read applicability and consequences before deciding to use a pattern.
  • Start with the essential five; most real code uses a handful of patterns over and over.
Revision notes · 2 min

Core idea#

Every pattern description answers three questions: what problem, what solution, and what trade-offs. Once you know the template, you know where to look in any pattern write-up.

Key points#

  • Read the problem first. Without it, a pattern feels like a solution looking for a problem.
  • The intent is the one-line summary, the pattern's elevator pitch.
  • The motivation is the problem in a concrete scenario.
  • Read applicability and consequences before you decide to use a pattern.
  • Known uses show real systems. Related patterns point to look-alikes and partners.

The GoF template#

Section What it tells you
Name and classification The handle, and Creational, Structural or Behavioral
Intent / Also known as One-line purpose, and other names
Motivation / Applicability The problem in context, and where it fits
Structure / Participants / Collaborations Class diagram, roles, how they work together
Consequences / Implementation Trade-offs, tips, pitfalls and code

What to read first#

You are... Read first
Learning a pattern Intent → Motivation → Structure → Implementation
Evaluating whether it fits Applicability → Consequences → Known uses
Implementing it Implementation → Consequences → Related patterns

What to learn first#

  • Essential: Singleton, Factory Method, Observer, Strategy, Decorator.
  • Very useful: Adapter, Builder, Command, Facade, Iterator.
  • Good to know: Template Method, State, Proxy, Composite, Abstract Factory.

Pitfalls#

  • Skipping the problem and jumping to the structure diagram.
  • Adopting a pattern without reading its consequences. Observer, for example, brings memory leaks from forgotten observers and cascading updates.

Say it in an interview#

  • "A pattern is a problem, a solution and its consequences."
  • "Before I use one, I check applicability and the trade-offs."

Found a mistake? Email ask@bigonotes.com