public static function make($vehicle_type, $driving_style, $colour)
 {
     if ($vehicle_type == VehicleFactory::CAR) {
         $factory = new CarFactory();
     } else {
         $factory = new VanFactory();
     }
     return $factory->build($driving_style, $colour);
 }
Example #2
0
<?php

require_once 'imports.php';
$what_to_make = 'car';
// or 'van'
if ($what_to_make == 'car') {
    $factory = new CarFactory();
} else {
    $factory = new VanFactory();
}
// Create the vehicle's component parts...
// These will either be all car parts or all van parts
$vehicle_body = $factory->createBody();
$vehicle_chassis = $factory->createChassis();
$vehicle_windows = $factory->createWindows();
?>
<html>
	<body>
		<p><?php 
echo $vehicle_body->getBodyParts();
?>
</p>
		<p><?php 
echo $vehicle_chassis->getChassisParts();
?>
</p>
		<p><?php 
echo $vehicle_windows->getWindowParts();
?>
</p>
	</body>