Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
Parts #226 fixed Builder Sep 23, 2016
Tests Merge branch 'master' into feature/class-instead-of-namespace Mar 9, 2017
uml Added Creational pattern UMLs Jul 31, 2014
BuilderInterface.php PHP7 Builder Sep 22, 2016
CarBuilder.php #226 fixed Builder Sep 23, 2016
Director.php PHP7 Builder Sep 22, 2016
README.rst Improve grammar: these code > this code Apr 4, 2017
TruckBuilder.php #226 fixed Builder Sep 23, 2016

README.rst

Builder

Purpose

Builder is an interface that build parts of a complex object.

Sometimes, if the builder has a better knowledge of what it builds, this interface could be an abstract class with default methods (aka adapter).

If you have a complex inheritance tree for objects, it is logical to have a complex inheritance tree for builders too.

Note: Builders have often a fluent interface, see the mock builder of PHPUnit for example.

Examples

  • PHPUnit: Mock Builder

UML Diagram

Alt Builder UML Diagram

Code

You can also find this code on GitHub

Director.php

.. literalinclude:: Director.php
   :language: php
   :linenos:

BuilderInterface.php

.. literalinclude:: BuilderInterface.php
   :language: php
   :linenos:

TruckBuilder.php

.. literalinclude:: TruckBuilder.php
   :language: php
   :linenos:

CarBuilder.php

.. literalinclude:: CarBuilder.php
   :language: php
   :linenos:

Parts/Vehicle.php

.. literalinclude:: Parts/Vehicle.php
   :language: php
   :linenos:

Parts/Truck.php

.. literalinclude:: Parts/Truck.php
   :language: php
   :linenos:

Parts/Car.php

.. literalinclude:: Parts/Car.php
   :language: php
   :linenos:

Parts/Engine.php

.. literalinclude:: Parts/Engine.php
   :language: php
   :linenos:

Parts/Wheel.php

.. literalinclude:: Parts/Wheel.php
   :language: php
   :linenos:

Parts/Door.php

.. literalinclude:: Parts/Door.php
   :language: php
   :linenos:

Test

Tests/DirectorTest.php

.. literalinclude:: Tests/DirectorTest.php
   :language: php
   :linenos: