mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-09-25 13:59:08 +02:00
44 lines
1003 B
PHP
44 lines
1003 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Creational\Builder;
|
|
|
|
use DesignPatterns\Creational\Builder\Parts\Vehicle;
|
|
|
|
class CarBuilder implements Builder
|
|
{
|
|
/**
|
|
* @var Parts\Car
|
|
*/
|
|
private $car;
|
|
|
|
public function addDoors()
|
|
{
|
|
$this->car->setPart('rightDoor', new Parts\Door());
|
|
$this->car->setPart('leftDoor', new Parts\Door());
|
|
$this->car->setPart('trunkLid', new Parts\Door());
|
|
}
|
|
|
|
public function addEngine()
|
|
{
|
|
$this->car->setPart('engine', new Parts\Engine());
|
|
}
|
|
|
|
public function addWheel()
|
|
{
|
|
$this->car->setPart('wheelLF', new Parts\Wheel());
|
|
$this->car->setPart('wheelRF', new Parts\Wheel());
|
|
$this->car->setPart('wheelLR', new Parts\Wheel());
|
|
$this->car->setPart('wheelRR', new Parts\Wheel());
|
|
}
|
|
|
|
public function createVehicle()
|
|
{
|
|
$this->car = new Parts\Car();
|
|
}
|
|
|
|
public function getVehicle(): Vehicle
|
|
{
|
|
return $this->car;
|
|
}
|
|
}
|