System Design Academy

Saving…

Lesson 1 of 11 in Module 30 of 45 lessons complete

What Are Design Patterns?

Module 3, lesson 1Concept12 min

Definition

Design pattern

In plain English
A design pattern is a named, reusable solution shape for a problem that keeps coming up in code.
Think of it like
It is like a sewing pattern you adapt to each new piece of cloth rather than a finished shirt.

Why it exists

Ten teams describe the same design in ten different ways. You spend the meeting translating instead of deciding.

A shared pattern name shortens that discussion. Copying a pattern without its problem can still bury readable code under layers.

How it works

Creational, structural and behavioural

In plain English
Creational patterns are about creating values, structural patterns about fitting types together, and behavioural patterns about how types share work.
Think of it like
Like a kitchen's three jobs: buying ingredients, arranging stations and running the service.
PatternCategoryProblemGo shape
FactoryCreationalRepeated creation decisionsNewX function returning a value or interface
BuilderCreationalSettings need combined validationMethods collect settings; Build validates
SingletonCreationalOne expensive shared valueOne shared value with protected setup
AdapterStructuralMismatched interfacesWrapper translates method calls
DecoratorStructuralExtra behaviour around a valueWrapper keeps the same interface
StrategyBehaviouralInterchangeable ways to calculateFunction type or small interface
ObserverBehaviouralMany reactions to one eventA function or small interface
StateBehaviouralActions depend on lifecycle stageState types or a transition table
CommandBehaviouralActions need storage or undoState types or a table of allowed moves

Patterns branches to Creational, Structural and Behavioural, each linked to its named patterns.

Three families organise nine recurring problems.

Patterns branches to Creational, Structural and Behavioural, each linked to its named patterns.

Anti-pattern

In plain English
An anti-pattern is a common "solution" that looks helpful but causes more problems than it solves.
Think of it like
Like taping over a warning light instead of fixing the engine.

Examples

Name the notification shape

Ten services react when a robot finishes a pick. Observer names the shared design.

Complete library: name the notification shape.
Go
package notifications

type Hub interface {
	Subscribe(func(string))
	Publish(string)
}

Subscribe registers a function to call later. Publish announces an event to the registered functions.

The insight

A pattern name compresses a whole design into one word.

Trade-offs

Pros

  • Shared vocabulary.
  • Tested solution shapes.
  • Shorter design discussions.

Cons

  • Easy to over-apply.
  • Textbook forms can be heavier than Go needs.

Use when

  • You recognise a recurring problem.
  • A name helps your team discuss a design.

Avoid when

  • You want the design to sound professional.
  • A plain function already solves the problem.

Quick check

What is a design pattern?
Which category does Builder belong to?

Takeaways

  • Patterns are named solution shapes.
  • Three families: creational, structural, behavioural.
  • Start from the problem, not the pattern.

Try the quick check above whenever you feel ready.

Previous: DRY, KISS & YAGNI