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.
A short screencast showing how to implement a simple Factory Method in PHP.
A short screencast: the Abstract Factory pattern in PHP β products and factories built on shared interfaces.
A short screencast: the Builder pattern in PHP β assembling an immutable object through a fluent method chain.
A short screencast: the Prototype pattern in PHP β cloning an object via __clone() without re-running the constructor.
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.
A short screencast: the Adapter pattern in PHP β fitting an alien API into a single contract without touching legacy code.
A short screencast: the Bridge pattern in PHP β decoupling abstraction from implementation so both vary independently.
A short screencast: the Composite pattern in PHP β leaves and containers in one tree, a single render() call walks it all.
A short screencast: the Decorator pattern in PHP β wrapping an object and adding behavior on the fly, building a chain.
A short screencast: the Facade pattern in PHP β a simple entry point hiding a whole subsystem. Placing an order with a single line.
A short screencast: the Flyweight pattern in PHP β repeating state is shared between objects through a cache.
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.
A short screencast: the Chain of Responsibility pattern in PHP β a request travels along a chain of handlers until one of them handles it.
A short screencast: the Command pattern in PHP β a request becomes an object, and the invoker only calls its execution.
A short screencast: the Interpreter pattern in PHP β a grammar is expressed as a tree of objects, and every node evaluates itself.
A short screencast: the Iterator pattern in PHP β a uniform way to traverse a collection without exposing its internals.
A short screencast: the Mediator pattern in PHP β objects communicate through a mediator instead of talking to each other directly.
A short screencast: the Memento pattern in PHP β capture an object state so you can roll back to it later.
A short screencast: the Observer pattern in PHP β a publisher notifies subscribers about changes.
A short screencast: the State pattern in PHP β an object behavior changes depending on its current state.
A short screencast: the Strategy pattern in PHP β swap algorithms at runtime without changing the client.