![](https://keeplearning.dev/images/featured/should-a-function-or-method-have-only-one-return-statement-188e4d3d3614.png)
PHP
Here are my notes about creational design patterns with PHP examples.
1- Singleton Pattern: Involves a single class that is responsible to create an object while making sure that only a single object gets created.
2- Builder Pattern: The main purpose of the Builder design pattern is to separate the construction of a complex object from its representation.
3- Simple Factory Pattern: A basic factory class that has a method and this method returns different types of objects based on the given input.
4- Abstract Factory Pattern: This lets you produce families of related objects without specifying their concrete classes.
5- Static Factory Pattern: Used to create a series of related or dependent objects.
6- Factory Method Pattern: Known as Virtual Constructor.
This pattern provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.
7- Prototype Design Pattern: The main purpose of this pattern is to avoid the cost of creating new objects. With this pattern, we are trying to clone an object instead of creating a new one.
8- Pool Design Pattern: The main purpose of this pattern is storing initialized objects in a pool and when they are ready just use these ones. This avoids allocating and destroying costs.
You can check a worker example with this gist.
Also, you can check this example.
References:
Recommended Articles: