mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-20 21:42:20 +02:00
#226 fixed Builder
This commit is contained in:
44
Creational/Builder/TruckBuilder.php
Normal file
44
Creational/Builder/TruckBuilder.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Creational\Builder;
|
||||
|
||||
use DesignPatterns\Creational\Builder\Parts\Vehicle;
|
||||
|
||||
class TruckBuilder implements BuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var Parts\Truck
|
||||
*/
|
||||
private $truck;
|
||||
|
||||
public function addDoors()
|
||||
{
|
||||
$this->truck->setPart('rightDoor', new Parts\Door());
|
||||
$this->truck->setPart('leftDoor', new Parts\Door());
|
||||
}
|
||||
|
||||
public function addEngine()
|
||||
{
|
||||
$this->truck->setPart('truckEngine', new Parts\Engine());
|
||||
}
|
||||
|
||||
public function addWheel()
|
||||
{
|
||||
$this->truck->setPart('wheel1', new Parts\Wheel());
|
||||
$this->truck->setPart('wheel2', new Parts\Wheel());
|
||||
$this->truck->setPart('wheel3', new Parts\Wheel());
|
||||
$this->truck->setPart('wheel4', new Parts\Wheel());
|
||||
$this->truck->setPart('wheel5', new Parts\Wheel());
|
||||
$this->truck->setPart('wheel6', new Parts\Wheel());
|
||||
}
|
||||
|
||||
public function createVehicle()
|
||||
{
|
||||
$this->truck = new Parts\Truck();
|
||||
}
|
||||
|
||||
public function getVehicle(): Vehicle
|
||||
{
|
||||
return $this->truck;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user