Start here: what a design pattern is
A design pattern is a named, proven arrangement of classes and objects for a problem that keeps coming back. Knowing the name saves you from reinventing the arrangement, and lets you say in three words what would otherwise take a paragraph. This page introduces Pedal, the app every page builds, and shows how to read the pages.
1. What a pattern is, and isn't
Every pattern page in this track comes back to the same three things:
| Part | What it means | Example (factory method) |
|---|---|---|
| The problem | A pressure that keeps recurring in real code | The same "which class?" decision copied into several functions |
| The roles | Which objects exist and who calls whom | A creator with a method that subclasses override to make a product |
| The trade-off | What it costs, and when a simpler option is better | One more class per kind; overkill when only one kind exists |
A pattern is not a library you install or code you paste. It's a shape you adapt, and the same pattern looks different in Python, TypeScript and Java. Using one where the problem doesn't exist only adds classes; each page has a "When not to use it" section for that reason.
2. The three families
The 23 classic patterns, from the 1994 book by Gamma, Helm, Johnson and Vlissides, fall into three families. This track splits the last family in two, and adds a fifth group for patterns that are everywhere in modern code but newer than the book.
| Group in this track | The question it answers | Pages |
|---|---|---|
| Making objects | Who decides which class to create, and how is it put together? | 01–05 |
| Fitting objects together | How do objects wrap, stand in for, or combine with each other? | 06–12 |
| Choosing behaviour | How does the code pick, change or sequence what runs? | 13–17 |
| Objects talking | How do objects find out about, reach and walk each other? | 18–23 |
| Beyond the book | How do modern codebases wire and store objects, and which pattern fits? | 24–26 |
3. Meet Pedal
Pedal runs a city bike-share: 400 docking stations, 6,000 bikes, about 60,000 rides on a weekday. Riders unlock a bike at a dock, ride, return it at any dock with a free slot, and pay. Pay-as-you-go costs £1.00 to unlock plus £0.10 a minute; members pay no unlock fee and get 30 free minutes. The Architecture styles track builds Pedal at the scale of whole systems; this track zooms in on the classes inside.
Each pattern page starts from something Pedal genuinely needs: e-bikes and scooters joining the fleet, a second payment provider, bikes that break down, operators who need undo, marketing who want to write their own promo rules. The pain comes first, so the pattern has a reason to exist.
4. How to read a pattern page
| Section | What it gives you |
|---|---|
| 1 · The pain | Pedal's code before the pattern, and what hurts when the next change lands |
| 2 · The idea in one picture | An everyday analogy and a numbered figure of one call flowing through the roles |
| 3 · The roles | Each role, its job and its name in Pedal |
| 4 · Before and after | The same code both ways, and what the next three changes touch in each |
| 5 · The code | A complete program in Python, TypeScript and Java, compiled and run before publishing |
| 6 · Try it | A small lab for the pattern's central trade-off |
| 7 · When not to use it | Gains, costs, and the simpler or neighbouring option for each situation |
| 8 · How it goes wrong | The common ways the pattern is misused |
| 9 · Remember it and say it | A memory hook, and how to talk about it in an interview or code review |
| 10–11 | A short quiz (it feeds the review deck) and further reading |
5. Words every page uses
- Interface: the methods a caller can rely on, with no code behind them. Python uses an abstract base class or a protocol; TypeScript and Java have
interface. - Concrete class: a real class you can create with
new(or by calling it, in Python). - Composition: an object holding other objects and using them, instead of inheriting from them. Most patterns are built from it.
- Delegation: passing a call on to an object you hold. A decorator delegates to what it wraps.
- Polymorphism: calling the same method on different classes and getting each class's own behaviour.
- Client: on these pages, the code that uses a pattern (not a browser or an app).
Patterns lean on the SOLID principles, especially open-closed and dependency inversion. The Low-level design SOLID module covers them.
6. Check yourself
What is a design pattern?
Which of these is a good reason not to use a pattern?
Most patterns are built mainly from…
7. Glossary
Every dotted word in this track, in one place.