I was taking a look at the PHP Manual and saw an example implementation of the Factory
pattern.
Example:
class Exemplo
{
// Método Factory parametrizado
public static function factory($type)
{
if (include_once 'Drivers/' . $type . '.php') {
$classname = 'Driver_' . $type;
return new $classname;
} else {
throw new Exception ('Driver não encontrado');
}
}
}
Output:
// Carregar um driver MySQL
$mysql = Exemplo::factory('MySQL');
// Carregar um driver SQLite
$sqlite = Exemplo::factory('SQLite');
In the PHP of the Right Way , I saw that through Factory
, one class simply creates the object you would like to use .
I do not have any examples of Abstract Factory
, but I have already seen a course I did. And that confused me.
I would like to know, in the simplest possible way, what are the differences between these two patterns.