InterviewKata
Design patterns · Start here

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

Climbers name their knots: a figure-eight for tying in, a clove hitch for a quick anchor. Nobody invents a knot on the rock face. Each one has a job, a way it's tied, and a known weakness. A climber who says "clove hitch" has told the partner everything at once. Design patterns are named knots for code.

Every pattern page in this track comes back to the same three things:

PartWhat it meansExample (factory method)
The problemA pressure that keeps recurring in real codeThe same "which class?" decision copied into several functions
The rolesWhich objects exist and who calls whomA creator with a method that subclasses override to make a product
The trade-offWhat it costs, and when a simpler option is betterOne 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 trackThe question it answersPages
Making objectsWho decides which class to create, and how is it put together?01–05
Fitting objects togetherHow do objects wrap, stand in for, or combine with each other?06–12
Choosing behaviourHow does the code pick, change or sequence what runs?13–17
Objects talkingHow do objects find out about, reach and walk each other?18–23
Beyond the bookHow 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

SectionWhat it gives you
1 · The painPedal's code before the pattern, and what hurts when the next change lands
2 · The idea in one pictureAn everyday analogy and a numbered figure of one call flowing through the roles
3 · The rolesEach role, its job and its name in Pedal
4 · Before and afterThe same code both ways, and what the next three changes touch in each
5 · The codeA complete program in Python, TypeScript and Java, compiled and run before publishing
6 · Try itA small lab for the pattern's central trade-off
7 · When not to use itGains, costs, and the simpler or neighbouring option for each situation
8 · How it goes wrongThe common ways the pattern is misused
9 · Remember it and say itA memory hook, and how to talk about it in an interview or code review
10–11A short quiz (it feeds the review deck) and further reading

5. Words every page uses

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?

You adapt the shape; you don't paste code.

Which of these is a good reason not to use a pattern?

A pattern without its problem is only extra classes.

Most patterns are built mainly from…

Objects hold other objects behind an interface and delegate to them.

7. Glossary

Every dotted word in this track, in one place.

8. Where to go next