Introducing the factory pattern
The factory pattern is typically used in object-oriented programming and is defined as an object with the primary responsibility of creating other objects. An example from PHP might look like the following:
class Factory
{
    public static function build($carType)
    {
        if ($carType == "tesla") {
            return new Tesla();
        }
        if ($carType == "bmw") {
            return new BMW();
        }
    }
}
$myCar = Factory::build("tesla");
The factory class has a static method that accepts carType and returns a new instance. This is a very simple example, but we...