Files
DesignPatternsPHP/Creational/Prototype
MathiasReker 6ec696d00b Final public method for abstract class
All public methods of abstract classes should be final. Enforce API encapsulation in an inheritance architecture. If you want to override a method, use the Template method pattern.
2022-06-16 21:09:49 +02:00
..
2021-10-01 10:26:04 -03:00
2021-10-01 10:26:04 -03:00
2021-10-01 10:26:04 -03:00
2020-06-20 11:27:02 -03:00

`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
-----------

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

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:

.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/main/Creational/Prototype
.. __: http://en.wikipedia.org/wiki/Prototype_pattern