mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-09-25 05:51:46 +02:00
cs
This commit is contained in:
@@ -5,35 +5,51 @@ namespace DesignPatterns\Builder;
|
||||
/**
|
||||
* BikeBuilder builds bike
|
||||
*/
|
||||
class BikeBuilder implements Builder
|
||||
class BikeBuilder implements BuilderInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Parts\Bike
|
||||
*/
|
||||
protected $bike;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addDoors()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addEngine()
|
||||
{
|
||||
$this->bike->setPart('engine', new Parts\Engine());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addWheel()
|
||||
{
|
||||
$this->bike->setPart('forwardWheel', new Parts\Wheel());
|
||||
$this->bike->setPart('rearWheel', new Parts\Wheel());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createVehicle()
|
||||
{
|
||||
$this->bike = new Parts\Bike();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getVehicle()
|
||||
{
|
||||
return $this->bike;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ namespace DesignPatterns\Builder;
|
||||
* Note: Builders have often a fluent interface, see the mock builder of
|
||||
* PHPUnit for example.
|
||||
*/
|
||||
interface Builder
|
||||
interface BuilderInterface
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
@@ -5,7 +5,7 @@ namespace DesignPatterns\Builder;
|
||||
/**
|
||||
* CarBuilder builds car
|
||||
*/
|
||||
class CarBuilder implements Builder
|
||||
class CarBuilder implements BuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var Parts\Car
|
||||
|
@@ -14,8 +14,12 @@ class Director
|
||||
|
||||
/**
|
||||
* The director don't know 'bout concrete part
|
||||
*
|
||||
* @param BuilderInterface $builder
|
||||
*
|
||||
* @return Parts\Vehicle
|
||||
*/
|
||||
public function build(Builder $builder)
|
||||
public function build(BuilderInterface $builder)
|
||||
{
|
||||
$builder->createVehicle();
|
||||
$builder->addDoors();
|
||||
@@ -24,5 +28,4 @@ class Director
|
||||
|
||||
return $builder->getVehicle();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user