FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [View Raw Code]   [Original HTTPS Page]

DesignPatternsPHP/Creational/SimpleFactory at master · lyhistory/DesignPatternsPHP · GitHub

Repository navigation

Latest commit

 

History

History
 
 
  1. DesignPatternsPHP
  2. Creational

SimpleFactory

README.rst

Simple Factory

Purpose

ConcreteFactory is a simple factory pattern.

It differs from the static factory because it is NOT static and as you know: static => global => evil!

Therefore, you can have multiple factories, differently parametrized, you can subclass it and you can mock-up it.

UML Diagram

Code

You can also find these code on GitHub

ConcreteFactory.php

.. literalinclude:: ConcreteFactory.php
   :language: php
   :linenos:

VehicleInterface.php

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

Bicycle.php

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

Scooter.php

.. literalinclude:: Scooter.php
   :language: php
   :linenos:

Test

Tests/SimpleFactoryTest.php

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


Back | FazBrowse Home | New Git URL