<?php
interface IWheels{
public function drawWheels();
}
interface IHood{
public function drawHood();
}
interface IDoors{
public function drawDoors();
}
class SportCarWheels implements IWheels
{
public function drawWheels()
{
echo "Sport car wheels have been drown!</br>";
}
}
class TruckWheels implements IWheels
{
public function drawWheels()
{
echo "Truck wheels have been drown!</br>";
}
}
class SportCarHood implements IHood
{
public function drawHood()
{
echo "Sport car hood has been drown!</br>";
}
}
class TruckHood implements IHood
{
public function drawHood()
{
echo "Truck hood has been drown!</br>";
}
}
class SportCarDoors implements IDoors
{
public function drawDoors()
{
echo "Sport car doors have been drown!</br>";
}
}
class TruckDoors implements IDoors
{
public function drawDoors()
{
echo "Truck doors have been drown!</br>";
}
}
/**
* Interface ICar is abstract factory
*/
interface ICar
{
public function draw();
}
abstract class Car implements ICar
{
protected $wheels;
protected $hood;
protected $doors;
public function draw()
{
$this->wheels->drawWheels();
$this->hood->drawHood();
$this->doors->drawDoors();
}
}
/**
* Class SportCar is concrete factory
*/
class SportCar extends Car
{
public function __construct()
{
$this->wheels = new SportCarWheels();
$this->hood = new SportCarHood();
$this->doors = new SportCarDoors();
}
}
/**
* Class Truck is concrete factory
*/
class Truck extends Car
{
public function __construct()
{
$this->wheels = new TruckWheels();
$this->hood = new TruckHood();
$this->doors = new TruckDoors();
}
}
// Client code
// Choose car type
$carType = "sport";
if ($carType == "sport") {
$car = new SportCar();
}
elseif ($carType == "truck") {
$car = new Truck();
}
$car->draw();