Design Patterns

All 23 Gang of Four design patterns, each with a narrated video, a running Java example, a class diagram, and advice on when not to use it.

Creational

How objects get made: hide which class is built, and how.

Factory Method

Fifty lines of spawn code and one new Wolf() in the middle. Learn how Factory Method lets the parent keep the steps while each subclass picks the class, and how it differs from its look-alikes.

Abstract Factory

A photo is saved on a laptop while its thumbnail job goes to the cloud: file not found. Learn how one factory per family keeps related objects matching, what it costs, and when to skip it.

Builder Pattern

Thirty, thin, true, false, true, true, true. Learn how the Builder pattern turns unreadable constructors into a readable, validated, immutable object: order step by step, bake once.

Prototype

A diagram editor has to duplicate shapes it only knows as Shape. Learn how Prototype lets each shape copy itself, why a shallow copy of a group shares its children, and when not to copy at all.

Singleton

Three services each open a connection pool and the database falls over. Learn what Singleton promises, how to write it correctly, what it costs, and why most code should make one and pass it in.

Structural

How classes and objects are composed into larger structures.

Adapter

Twelve call sites print receipts, and the new printer only speaks bytes. Learn how one Adapter class lets your code keep its own interface, and how it differs from Decorator, Proxy and Facade.

Bridge

Three kinds of notification and three channels make nine classes, and Slack makes twelve. Learn how Bridge turns that into three plus three, and how it differs from Adapter and Strategy.

Composite

Splitting one task into a sub-phase silently drops sixteen hours from an estimate. Learn how the Composite pattern makes a group just another item, how the recursion works, and where Swing and file trees use it.

Decorator Pattern

Seven classes for three features, or three small wrappers? Learn how the Decorator pattern adds one job at a time through the same interface, with plug-in adapters, java.io streams, diagrams, Java code and a narrated video.

Facade

Publishing a podcast episode takes six calls to five classes, and three clients repeat them. Learn how a Facade gives the common task one front door while the back doors stay open.

Flyweight

A map app with 100,000 pins crashes because every pin carries its own copy of an icon. Learn how Flyweight splits shared state from per-object state, and when it isn't worth it.

Proxy

A playlist of two hundred songs stays blank for twenty seconds. Learn how a Proxy that looks exactly like the real object decides when, whether and where a call gets through, and how it differs from Decorator and Adapter.

Behavioral

How objects share responsibility and talk to each other.

Chain of Responsibility Pattern

Who signs a 3,000 expense? Learn how the Chain of Responsibility pattern lets a request find its own handler, with diagrams, Java code, servlet filters, and a narrated video.

Command Pattern

How does Ctrl+Z know what to undo? Learn how the Command pattern turns a call into an object you can store, queue, combine and reverse, with diagrams, Java code, and a narrated video.

Interpreter

Feature-flag rules hard-coded in if chains mean a deploy for every change. Learn how Interpreter turns a small grammar into classes and a sentence into a tree, and where it stops being a good idea.

Iterator

A playlist changes how it stores songs and twelve loops break. Learn how an iterator hides a collection's insides, how to remove safely while looping, how to page an API, and when streams fit better.

Mediator

A signup button's enable rule lives in four widgets, and one of them forgot the checkbox. Learn how a Mediator turns twenty links between five widgets into five, and how to keep the hub from becoming a god object.

Memento

A platform game needs checkpoints. Learn how Memento lets the game snapshot its own private state, why the save slots must never read it, and when snapshots beat commands.

Observer Pattern

A delayed flight, a bookshop sign-up sheet and a dark-mode toggle. Learn how the Observer pattern lets one object announce changes without knowing who listens, with diagrams, Java code and a narrated video.

State Pattern

One object, one button, different behavior. Learn how the State pattern groups code by state instead of by event, with diagrams, Java examples, and a narrated video.

Strategy Pattern

One trip, three routes. Learn how the Strategy pattern keeps the what in one place and lets the client swap the how, with diagrams, Java code, lambdas, and a narrated video.

Template Method Pattern

Same report, two answers. Learn how the Template Method pattern fixes the skeleton of an algorithm and lets subclasses fill in the steps, with diagrams, Java code, and a narrated video.

Visitor

A page editor's three block classes keep gaining operations. Learn how double dispatch lets one accept method serve any number of visitors, what it costs, and when a sealed interface and a pattern switch is the better answer.