1.2.36. An OOP Factory¶
A method or function that implements a factory. A factory is a class that handles the creation of an object, based on parameters. The factory hides the logic that leads to the creation of the object.
<?php
class AutomobileFactory {
public static function create($make, $model) {
$className = "\Automaker\Brand$make";
return new $className($model);
}
}
// The factory is able to build any car, based on their
$fuego = AutomobileFactory::create('Renault', 'Fuego');
print_r($fuego->getMakeAndModel()); // outputs "Renault Fuego"
?>
See also Factory (object-oriented programming) and Factory.
1.2.36.1. Connex PHP features¶
1.2.36.1.1. Specs¶
Short name |
Patterns/Factory |
Rulesets |
|
Exakat since |
1.6.7 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |