Skip to content

Instantly share code, notes, and snippets.

@HoangPV
Created July 28, 2017 03:09
Show Gist options
  • Save HoangPV/2b45004edf2699d0d49128275b516361 to your computer and use it in GitHub Desktop.
Save HoangPV/2b45004edf2699d0d49128275b516361 to your computer and use it in GitHub Desktop.
have the factory create the Automobile object
<?php
class Automobile
{
private $vehicleMake;
private $vehicleModel;
public function __construct($make, $model)
{
$this->vehicleMake = $make;
$this->vehicleModel = $model;
}
public function getMakeAndModel()
{
return $this->vehicleMake . ' ' . $this->vehicleModel;
}
}
class AutomobileFactory
{
public static function create($make, $model) {
return new Automobile($make, $model);
}
}
// have the factory create the Automobile object
$veyron = AutomobileFactory::create('Bugatti', 'Veyron');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment