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.

Creational Structural Behavioural
#01 Structural

Bridge

Decouples an abstraction from its implementation so both can vary independently.

Open demo →
#02 Behavioural

Strategy

Defines a family of algorithms, encapsulates each one, and makes them interchangeable.

Open demo →
#03 Creational

Singleton

Ensures a class has only one instance and provides a global access point to it.

Open demo →
#04 Creational

Monostate

Multiple instances all share the same underlying state via static properties.

Open demo →
#05 Creational

Factory

Delegates object creation to a factory method, hiding the concrete class from the caller.

Open demo →
#06 Structural

Proxy

Provides a surrogate that controls access to the real object — e.g. lazy loading.

Open demo →
#07 Behavioural

Observer

One-to-many dependency: when one object changes state, all dependents are notified.

Open demo →
#08 Behavioural

Mediator

Centralises complex communications between objects into a single mediator class.

Open demo →
#09 Behavioural

Null Object

Replaces null checks by providing a do-nothing object that honours the expected interface.

Open demo →
#10 Structural

Adapter

Converts an incompatible interface into one the client expects — a "translator" class.

Open demo →
#11 Structural

Facade

Provides a simple, unified interface to a complex subsystem of classes.

Open demo →
#12 Behavioural

Visitor

Adds new operations to objects without changing their classes — double dispatch.

Open demo →
#13 Structural

Decorator

Attaches additional responsibilities to an object dynamically, wrapping it at runtime.

Open demo →
#14 Structural

Composite

Composes objects into tree structures and treats individual objects and composites uniformly.

Open demo →
#15 Behavioural

State

Lets an object alter its behaviour when its internal state changes — appears to change class.

Open demo →
#16 Behavioural

Command

Encapsulates a request as an object, supporting undo, queuing, and logging.

Open demo →
#17 Behavioural

Template Method

Defines the skeleton of an algorithm; subclasses fill in specific steps without changing the structure.

Open demo →
#18 Structural

Repository

Abstracts data access behind an interface, so callers never depend on where or how data is stored.

Open demo →
#19 Behavioural

Active Object

Decouples method invocation from method execution — calls return immediately, the real work happens via a queue.

Open demo →
#20 Structural

Reflection

Inspects a class's own constructor at runtime to auto-resolve its dependencies — the mechanism behind Laravel's Service Container.

Open demo →
#21 Creational

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.

Open demo →
#22 Structural

Abstract Server

The client depends only on an abstract interface, never a concrete class — the general principle underlying both Adapter and Bridge.

Open demo →