PHP Design Patterns¶
Practical, minimal PHP implementations of the most important design patterns and SOLID principles.
Each example is self-contained, focused, and written to be read — not just run.
Work in Progress
This project is actively being expanded. More design patterns and SOLID principles will be added over time.
What's Inside¶
Patterns that define how objects communicate and delegate responsibility.
| Pattern | Intent |
|---|---|
| Observer | Notify dependents automatically when state changes |
| Strategy | Swap algorithms at runtime without changing the caller |
| Template Method | Define a skeleton algorithm; let subclasses fill in the steps |
Patterns that control how objects are created.
| Pattern | Intent |
|---|---|
| Abstract Factory | Create families of related objects without specifying concrete classes |
| Factory Method | Delegate instantiation to subclasses |
| Simple Factory | Centralise object creation behind a single method |
Patterns that describe how objects are composed.
| Pattern | Intent |
|---|---|
| Composite | Treat individual objects and compositions uniformly |
Principles that guide writing maintainable, extensible code.
| Principle | Summary |
|---|---|
| Single Responsibility | A class should have only one reason to change |