PHP Design Patterns
An interactive teaching aid for the classic Gang of Four patterns, plus core Laravel mechanisms. Click any card to open a live, interactive demonstration.
Bridge
Decouples an abstraction from its implementation so both can vary independently.
Strategy
Defines a family of algorithms, encapsulates each one, and makes them interchangeable.
Singleton
Ensures a class has only one instance and provides a global access point to it.
Monostate
Multiple instances all share the same underlying state via static properties.
Factory
Delegates object creation to a factory method, hiding the concrete class from the caller.
Proxy
Provides a surrogate that controls access to the real object — e.g. lazy loading.
Observer
One-to-many dependency: when one object changes state, all dependents are notified.
Mediator
Centralises complex communications between objects into a single mediator class.
Null Object
Replaces null checks by providing a do-nothing object that honours the expected interface.
Adapter
Converts an incompatible interface into one the client expects — a "translator" class.
Facade
Provides a simple, unified interface to a complex subsystem of classes.
Visitor
Adds new operations to objects without changing their classes — double dispatch.
Decorator
Attaches additional responsibilities to an object dynamically, wrapping it at runtime.
Composite
Composes objects into tree structures and treats individual objects and composites uniformly.
State
Lets an object alter its behaviour when its internal state changes — appears to change class.
Command
Encapsulates a request as an object, supporting undo, queuing, and logging.
Template Method
Defines the skeleton of an algorithm; subclasses fill in specific steps without changing the structure.
Repository
Abstracts data access behind an interface, so callers never depend on where or how data is stored.
Active Object
Decouples method invocation from method execution — calls return immediately, the real work happens via a queue.
Reflection
Inspects a class's own constructor at runtime to auto-resolve its dependencies — the mechanism behind Laravel's Service Container.
Service Container
Controls how objects get built: bind() for a new instance every time, singleton() to share one, instance() for pre-built objects, and contextual binding for per-consumer overrides.
Abstract Server
The client depends only on an abstract interface, never a concrete class — the general principle underlying both Adapter and Bridge.