Files
DesignPatternsPHP/Creational/SimpleFactory
Nikita Strelkov f862fba24e Move usage code exaple to single file and correctly include it
This make code more structured and fix code highlighting problem
2016-10-03 06:25:33 +05:00
..
2016-09-22 15:05:25 +02:00
2016-09-22 15:05:25 +02:00
2016-09-22 15:05:25 +02:00
2016-09-22 15:05:25 +02:00

Simple Factory
==============

Purpose
-------

SimpleFactory is a simple factory pattern.

It differs from the static factory because it is not static.
Therefore, you can have multiple factories, differently parametrized, you can subclass it and you can mock it.
It always should be preferred over a static factory!

UML Diagram
-----------

.. image:: uml/uml.png
   :alt: Alt SimpleFactory UML Diagram
   :align: center

Code
----

You can also find these code on `GitHub`_

SimpleFactory.php

.. literalinclude:: SimpleFactory.php
   :language: php
   :linenos:

VehicleInterface.php

.. literalinclude:: VehicleInterface.php
   :language: php
   :linenos:

Bicycle.php

.. literalinclude:: Bicycle.php
   :language: php
   :linenos:

Usage
-----

Usage/SimpleFactoryUsage.php

.. literalinclude:: Usage/SimpleFactoryUsage.php
   :language: php
   :linenos:

Test
----

Tests/SimpleFactoryTest.php

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

.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Creational/SimpleFactory