Skip to content

Files

Latest commit

2f467fe · Apr 4, 2017

History

History
This branch is 2 commits ahead of, 452 commits behind DesignPatternsPHP/DesignPatternsPHP:main.

Prototype

Purpose

To avoid the cost of creating objects the standard way (new Foo()) and instead create a prototype and clone it.

Examples

  • Large amounts of data (e.g. create 1,000,000 rows in a database at once via a ORM).

UML Diagram

Alt Prototype UML Diagram

Code

You can also find this code on GitHub

BookPrototype.php

.. literalinclude:: BookPrototype.php
   :language: php
   :linenos:

BarBookPrototype.php

.. literalinclude:: BarBookPrototype.php
   :language: php
   :linenos:

FooBookPrototype.php

.. literalinclude:: FooBookPrototype.php
   :language: php
   :linenos:

Test

Tests/PrototypeTest.php

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