The Factory Pattern in PHP 5


The factory is one of the most common OOP patterns. The concept of the factory pattern is pretty straight forward. The factory pattern uses a class that has methods that create objects rather than creating the objects directly.

Example factory pattern

Instead of just instantiating the class directly below:

You would make another class (this is where the factory part comes in):

you would use the above class by: