Everyweek a new Pattern + Article on www.medium.com/@anhaia.gabriel and www.medium.com/mestredev
PHP 8.1 - Design Patterns
This repository was created to show the implementation of a variety of Design Patterns using PHP 8. There is no dependency on a framework, and the examples are the most real as possible based on my own experiences solving real-life problems. Once you learn the design pattern and its concept, it will be effortless to apply it in any PHP project.
Patterns implemented + Article
# | |
Code Example / Implementation | |
---|---|---|---|
1 | Adapter | HERE | LEARN HERE
|
2 | Facade | HERE | LEARN HERE
|
3 | Template Method | HERE | LEARN HERE
|
4 | Strategy | HERE | LEARN HERE
|
5 | Abstract Factory | HERE | Soon |
6 | Builder | HERE | Soon |
7 | Composite | HERE | Soon |
8 | Decorator | HERE | Soon |
9 | Factory Method | HERE | Soon |
10 | Flyweight | HERE | Soon |
11 | Iterator | HERE | Soon |
12 | Memento | HERE | Soon |
13 | Money | HERE | Soon |
14 | Null Object | HERE | Soon |
15 | Observer | HERE | Soon |
16 | Prototype | HERE | Soon |
17 | Proxy | HERE | Soon |
18 | Singleton | HERE | Soon |
19 | State | HERE | Soon |
Coming soon
- Bridge
- Chain of Responsibility
- Command
- Interpreter
- Mediator
- Object Pool
- Visitor
Dependencies
Running the project
I strongly recommend that you follow the articles (links above) and run them with Docker. It will be much easier, and you need to install Docker on your computer, independent of the OS you are using. With a few commands, you will run/test all the Design Patterns implemented throughout the course .
Build de container:
# docker build -t design-patterns .
or if you prefer # make build
Run the following commands in order to test the design patterns:
# make help
and then you will see the list of commands
You just need to run the command with the pattern you want to test, for example:
# make strategy
Additional Information
- If you take a look at the examples into the blog, or inside the folders
/src/{$pattern_name}/
you will notice that in almost all the examples contain a folder calledcomponents
, those folders are the files/classes used to demonstrate how to use each pattern. Never consider what is in there as part of the pattern! They are not examples to be followed in your applications.