Design Patterns

All 23 GoF patterns. Popularity reflects how often each pattern shows up in real production code, not how useful it is to know.

behavioral

Chain of Responsibility
Passes a request along a chain of handlers. Each handler decides to process the request or forward it. Decouples senders from receivers without hardcoding which handler responds.
Command
Encapsulates a request as an object. Enables queuing, logging, and undoable operations by treating actions as first-class values that can be stored and passed around.
Interpreter
Defines a grammar and an interpreter for a simple language. Rarely built from scratch today — parser-combinator libraries and parser generators cover this use case more reliably.
Iterator
Provides sequential access to elements of a collection without exposing its internal representation. Built into most modern languages as a core protocol, rarely implemented manually.
Mediator
Centralizes communication between objects through a mediator object. Reduces direct dependencies, but concentrates logic — a mediator that grows too large becomes a god object.
Memento
Captures an object's internal state so it can be restored later, without exposing that state to the outside. The basis of undo/redo in editors and command processors.
Observer
Defines a one-to-many dependency so that when one object changes state, all dependents are notified. The foundation of event systems and reactive programming.
State
Lets an object change its behavior when its internal state changes. Replaces large conditionals on state flags with distinct state objects that handle behavior directly.
Strategy
Defines a family of algorithms, encapsulates each one, and makes them interchangeable. Lets the algorithm vary independently from the clients that use it.
Template Method
Defines the skeleton of an algorithm in a base class and defers specific steps to subclasses. Subclasses override individual steps without changing the overall structure.
Visitor
Lets you add operations to objects without modifying them. Separates an algorithm from the object structure it operates on, at the cost of making it hard to add new types.