Design Patterns

All 23 classic Gang of Four patterns for object-oriented software design.

Creational

Abstract Factory

Produces whole families of related objects through one interface, so the objects always match.

Creational

Builder

Assembles a complex object step by step, so the same steps can yield different configurations.

Creational

Factory Method

Delegates object creation to a method subclasses can override, hiding the exact type being built.

Creational

Prototype

Creates new objects by cloning an existing instance instead of building one from scratch.

Creational

Singleton

Guarantees a class has exactly one instance and gives the whole program one way to reach it.

Structural

Adapter

Wraps an object with a mismatched interface so it can work with code that expects a different one.

Structural

Bridge

Splits a class into two independent hierarchies - abstraction and implementation - connected through composition.

Structural

Composite

Lets individual objects and groups of them be handled through the same interface, regardless of nesting depth.

Structural

Decorator

Adds new behavior to a single object by wrapping it in layers that share its interface.

Structural

Facade

Hides a tangle of interacting classes behind one simple entry point.

Structural

Flyweight

Shares the common data of many similar objects to cut memory usage.

Structural

Proxy

Stands in for another object behind the same interface, intercepting calls to add checks, caching, or lazy loading.

Behavioral

Chain of Responsibility

Passes a request along a line of handlers until one of them takes care of it.

Behavioral

Command

Wraps a request as a standalone object, so it can be queued, logged, or undone independently of its trigger.

Behavioral

Interpreter

Represents each grammar rule of a small language as a class, so a sentence becomes a tree that can evaluate itself.

Behavioral

Iterator

Provides one consistent way to walk through a collection without exposing how it's stored.

Behavioral

Mediator

Moves the tangled communication between a group of objects into one go-between object.

Behavioral

Memento

Captures an object's state in a snapshot that can restore it later without exposing its internals.

Behavioral

Observer

Lets any number of objects subscribe to and get notified about another object's changes.

Behavioral

State

Lets an object change its entire behavior at runtime by switching between interchangeable state objects.

Behavioral

Strategy

Packages interchangeable algorithms into their own classes so they can be swapped at runtime.

Behavioral

Template Method

Fixes the overall steps of an algorithm in a base class while letting subclasses fill in the details.

Behavioral

Visitor

Moves an operation out of the classes it works on and into its own class, so adding operations doesn't require changing those classes.