mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-24 01:32:22 +01:00
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Creational\Builder;
|
|
|
|
use DesignPatterns\Creational\Builder\Parts\Door;
|
|
use DesignPatterns\Creational\Builder\Parts\Engine;
|
|
use DesignPatterns\Creational\Builder\Parts\Wheel;
|
|
use DesignPatterns\Creational\Builder\Parts\Truck;
|
|
use DesignPatterns\Creational\Builder\Parts\Vehicle;
|
|
|
|
class TruckBuilder implements Builder
|
|
{
|
|
private Truck $truck;
|
|
|
|
public function addDoors()
|
|
{
|
|
$this->truck->setPart('rightDoor', new Door());
|
|
$this->truck->setPart('leftDoor', new Door());
|
|
}
|
|
|
|
public function addEngine()
|
|
{
|
|
$this->truck->setPart('truckEngine', new Engine());
|
|
}
|
|
|
|
public function addWheel()
|
|
{
|
|
$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());
|
|
}
|
|
|
|
public function createVehicle()
|
|
{
|
|
$this->truck = new Truck();
|
|
}
|
|
|
|
public function getVehicle(): Vehicle
|
|
{
|
|
return $this->truck;
|
|
}
|
|
}
|