了解如何将最重要的设计模式应用到您的 PHP 应用中。本项目使用 PHP 8+,包含每个模式的示例以及一篇文章。
了解如何将最重要的设计模式应用到您的 PHP 应用中。本项目使用 PHP 8+,包含每个模式的示例以及一篇文章。
Learn how to implement the most important Design Patterns in PHP. This repository contains 26 patterns with real-world examples, runnable code, class diagrams, and companion articles.
No framework dependencies. Every example is based on real problems and can be applied directly to any PHP project.
New patterns and articles published on Medium @devwarlocks and Medium @anhaia.gabriel.
| Type | General Article | Diagrams |
|---|---|---|
| Learn here | Diagrams | |
| SOON | Diagrams | |
| SOON | Diagrams |
| # | Pattern | Code | Article | Diagram |
|---|---|---|---|---|
| 1 | Abstract Factory | Source | SOON | Diagram |
| 2 | Builder | Source | SOON | Diagram |
| 3 | Factory Method | Source | Read | Diagram |
| 4 | Prototype | Source | SOON | Diagram |
| 5 | Singleton | Source | SOON | Diagram |
| 6 | Object Pool | Source | SOON | Diagram |
| # | Pattern | Code | Article | Diagram |
|---|---|---|---|---|
| 7 | Adapter | Source | Read | Diagram |
| 8 | Composite | Source | Read | Diagram |
| 9 | Bridge | Source | SOON | Diagram |
| 10 | Facade | Source | Read | Diagram |
| 11 | Decorator | Source | SOON | Diagram |
| 12 | Flyweight | Source | SOON | Diagram |
| 13 | Proxy | Source | SOON | Diagram |
| # | Pattern | Code | Article | Diagram |
|---|---|---|---|---|
| 14 | Template Method | Source | Read | Diagram |
| 15 | Strategy | Source | Read | Diagram |
| 16 | Iterator | Source | SOON | Diagram |
| 17 | Memento | Source | SOON | Diagram |
| 19 | Null Object | Source | SOON | Diagram |
| 20 | Observer | Source | Read | Diagram |
| 21 | State | Source | SOON | Diagram |
| 22 | Command | Source | SOON | Diagram |
| 23 | Chain of Responsibility | Source | SOON | Diagram |
| 24 | Interpreter | Source | SOON | Diagram |
| 25 | Mediator | Source | SOON | Diagram |
| 26 | Visitor | Source | Read | Diagram |
| # | Pattern | Code | Article | Diagram |
|---|---|---|---|---|
| 18 | Money | Source | Read | Diagram |
make buildor
docker build -t design-patterns .make helpmake strategymake strategy-helpIf you look at the examples inside each /src/{pattern_name}/ folder, you'll notice most contain a components subfolder. These files are supporting classes used to demonstrate the pattern in action. They are not part of the pattern itself and should not be taken as examples to follow in your own applications.
This project is licensed under the MIT License - see the LICENSE file for details.
If this project helped you learn, consider giving it a star or buying me a coffee.
暂无开放 Issues,或尚未同步最近议题。