48 lines
1.2 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
2016-09-23 11:29:28 +02:00
namespace DesignPatterns\Creational\Builder;
2019-12-14 12:50:05 +01:00
use DesignPatterns\Creational\Builder\Parts\Door;
use DesignPatterns\Creational\Builder\Parts\Engine;
use DesignPatterns\Creational\Builder\Parts\Wheel;
use DesignPatterns\Creational\Builder\Parts\Truck;
2016-09-23 11:29:28 +02:00
use DesignPatterns\Creational\Builder\Parts\Vehicle;
2019-08-19 17:00:34 +02:00
class TruckBuilder implements Builder
2016-09-23 11:29:28 +02:00
{
2019-12-14 12:50:05 +01:00
private Truck $truck;
2016-09-23 11:29:28 +02:00
public function addDoors()
{
2019-12-14 12:50:05 +01:00
$this->truck->setPart('rightDoor', new Door());
$this->truck->setPart('leftDoor', new Door());
2016-09-23 11:29:28 +02:00
}
public function addEngine()
{
2019-12-14 12:50:05 +01:00
$this->truck->setPart('truckEngine', new Engine());
2016-09-23 11:29:28 +02:00
}
public function addWheel()
{
2019-12-14 12:50:05 +01:00
$this->truck->setPart('wheel1', new Wheel());
$this->truck->setPart('wheel2', new Wheel());
$this->truck->setPart('wheel3', new Wheel());
$this->truck->setPart('wheel4', new Wheel());
$this->truck->setPart('wheel5', new Wheel());
$this->truck->setPart('wheel6', new Wheel());
2016-09-23 11:29:28 +02:00
}
public function createVehicle()
{
2019-12-14 12:50:05 +01:00
$this->truck = new Truck();
2016-09-23 11:29:28 +02:00
}
public function getVehicle(): Vehicle
{
return $this->truck;
}
}