What is a Design Pattern?
Design patterns are typical solutions to common problems in software design. Each pattern is like a blueprint that you can customize to solve a particular design problem in your code.
You can’t just find a pattern and copy it into your program, the way you can with off-the-shelf functions or libraries. The pattern is not a specific piece of code, but a general concept for solving a particular problem. You can follow the pattern details and implement a solution that suits the realities of your own program.
Patterns are often confused with algorithms, because both concepts describe typical solutions to some known problems. While an algorithm always defines a clear set of actions that can achieve some goal, a pattern is a more high-level description of a solution. The code of the same pattern applied to two different programs may be different.
An analogy to an algorithm is a cooking recipe: both have clear steps to achieve a goal. On the other hand, a pattern is more like a blueprint: you can see what the result and its features are, but the exact order of implementation is up to you.
Implemented Design Patterns
-
Creational patterns - These patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code.
- Abstract Factory Design Pattern
- Factory Design Pattern
- Singleton Design Pattern
- Prototype Design Pattern
- Builder Design Pattern
-
Structural patterns - These patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.
- Adapter Design Pattern
- Bridge Design Pattern
- Composite Design Pattern
- Facade Design Pattern
-
Behavioral patterns - These patterns are concerned with algorithms and the assignment of responsibilities between objects.
Installation
git clone https://github.com/bakhtiyor/design-patterns design-patterns
cd design-patterns
composer install
php example/[name-of-file.php]