Skip to main content

What Is a Design Pattern

A design pattern is a named, proven solution to a problem that keeps coming back in software design. Patterns are not code you copy — they are shapes you recognize: "this is a wrapping problem", "this is a notification problem".

The classic catalog contains 23 patterns, collected by four authors known as the Gang of Four. Knowing them gives you two things: ready answers to common problems, and a shared vocabulary — saying "use an adapter here" replaces a whole paragraph of explanation.


The Three Families

The 23 patterns fall into three families:

Creational — how objects get made: Singleton, Factory Method, Abstract Factory, Builder, Prototype.

Structural — how things fit together: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy.

Behavioral — how things talk to each other: Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor.

Each pattern in this group has its own page: what it is, one runnable example, when to use it, and its pros and cons.


Patterns the PHP Way

The catalog was written for languages built around classes and inheritance — and PHP is one of them. Classes, interfaces and inheritance map directly onto the classic catalog, and every page here uses them.

PHP also has closures, and the function-shaped patterns get simpler with them — a strategy can be just a function you pass around. Each page shows the shape that fits PHP best.

One warning before you start: patterns are tools, not goals. Using a pattern where a plain function would do makes code worse. Reach for a pattern when you feel its problem — never before.