Programming Patterns

A catalog of design patterns in PHP with explanations and examples.

Creational

Object-creation patterns: how creating an object is decoupled from using it.

PHP Factory Pattern
PHP Factory Design Pattern Creational Pattern
PHP Factory Pattern

A short screencast showing how to implement a simple Factory Method in PHP.

PHP Abstract Factory Pattern
PHP Abstract Factory Design Pattern Creational Pattern
PHP Abstract Factory Pattern

A short screencast: the Abstract Factory pattern in PHP β€” products and factories built on shared interfaces.

PHP Builder Pattern
PHP Builder Design Pattern Creational Pattern
PHP Builder Pattern

A short screencast: the Builder pattern in PHP β€” assembling an immutable object through a fluent method chain.

PHP Prototype Pattern
PHP Prototype Design Pattern Creational Pattern
PHP Prototype Pattern

A short screencast: the Prototype pattern in PHP β€” cloning an object via __clone() without re-running the constructor.

PHP Singleton Pattern
PHP Singleton Design Pattern Creational Pattern
PHP Singleton Pattern

A short screencast: the Singleton pattern in PHP β€” one object for the whole app with lazy initialization.

Structural

Composition patterns: how classes and objects are assembled into larger structures.

PHP Adapter Pattern
PHP Adapter Design Pattern Structural Pattern
PHP Adapter Pattern

A short screencast: the Adapter pattern in PHP β€” fitting an alien API into a single contract without touching legacy code.

PHP Bridge Pattern
PHP Bridge Design Pattern Structural Pattern
PHP Bridge Pattern

A short screencast: the Bridge pattern in PHP β€” decoupling abstraction from implementation so both vary independently.

PHP Composite Pattern
PHP Composite Design Pattern Structural Pattern
PHP Composite Pattern

A short screencast: the Composite pattern in PHP β€” leaves and containers in one tree, a single render() call walks it all.

PHP Decorator Pattern
PHP Decorator Design Pattern Structural Pattern
PHP Decorator Pattern

A short screencast: the Decorator pattern in PHP β€” wrapping an object and adding behavior on the fly, building a chain.

PHP Facade Pattern
PHP Facade Design Pattern Structural Pattern
PHP Facade Pattern

A short screencast: the Facade pattern in PHP β€” a simple entry point hiding a whole subsystem. Placing an order with a single line.

PHP Flyweight Pattern
PHP Flyweight Design Pattern Structural Pattern
PHP Flyweight Pattern

A short screencast: the Flyweight pattern in PHP β€” repeating state is shared between objects through a cache.

PHP Proxy Pattern
PHP Proxy Design Pattern Structural Pattern
PHP Proxy Pattern

A short screencast: the Proxy pattern in PHP β€” a surrogate object controls access and adds lazy loading with caching.

Behavioral

Interaction patterns: how objects communicate and share responsibilities.

PHP Chain of Responsibility Pattern
PHP Chain of Responsibility Design Pattern Behavioral Pattern
PHP Chain of Responsibility Pattern

A short screencast: the Chain of Responsibility pattern in PHP β€” a request travels along a chain of handlers until one of them handles it.

PHP Command Pattern
PHP Command Design Pattern Behavioral Pattern
PHP Command Pattern

A short screencast: the Command pattern in PHP β€” a request becomes an object, and the invoker only calls its execution.

PHP Interpreter Pattern
PHP Interpreter Design Pattern Behavioral Pattern
PHP Interpreter Pattern

A short screencast: the Interpreter pattern in PHP β€” a grammar is expressed as a tree of objects, and every node evaluates itself.

PHP Iterator Pattern
PHP Iterator Design Pattern Behavioral Pattern
PHP Iterator Pattern

A short screencast: the Iterator pattern in PHP β€” a uniform way to traverse a collection without exposing its internals.

PHP Mediator Pattern
PHP Mediator Design Pattern Behavioral Pattern
PHP Mediator Pattern

A short screencast: the Mediator pattern in PHP β€” objects communicate through a mediator instead of talking to each other directly.

PHP Memento Pattern
PHP Memento Design Pattern Behavioral Pattern
PHP Memento Pattern

A short screencast: the Memento pattern in PHP β€” capture an object state so you can roll back to it later.

PHP Observer Pattern
PHP Observer Design Pattern Behavioral Pattern
PHP Observer Pattern

A short screencast: the Observer pattern in PHP β€” a publisher notifies subscribers about changes.

PHP State Pattern
PHP State Design Pattern Behavioral Pattern
PHP State Pattern

A short screencast: the State pattern in PHP β€” an object behavior changes depending on its current state.

PHP Strategy Pattern
PHP Strategy Design Pattern Behavioral Pattern
PHP Strategy Pattern

A short screencast: the Strategy pattern in PHP β€” swap algorithms at runtime without changing the client.