Files
DesignPatternsPHP/More/Delegation
Axel Pardemann 53bc377d88 Added missing PO templates
Also added some punctuation, grammar and style fixes to some RST files.
2016-09-22 12:50:30 -05:00
..
2015-12-21 07:28:20 -05:00
2014-07-31 14:13:53 -05:00
2015-12-21 07:28:20 -05:00
2016-09-22 12:50:30 -05:00
2015-12-21 07:28:20 -05:00

`Delegation`__
==============

Purpose
-------

Demonstrate the Delegator pattern, where an object, instead of performing one
of its stated tasks, delegates that task to an associated helper object. In
this case TeamLead professes to writeCode and Usage uses this, while TeamLead
delegates writeCode to JuniorDeveloper's writeBadCode function. This inverts
the responsibility so that Usage is unknowingly executing writeBadCode.

Examples
--------

Please review JuniorDeveloper.php, TeamLead.php, and then Usage.php to see it all tied together.

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

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

Code
----

You can also find these code on `GitHub`_

Usage.php

.. literalinclude:: Usage.php
   :language: php
   :linenos:

TeamLead.php

.. literalinclude:: TeamLead.php
   :language: php
   :linenos:

JuniorDeveloper.php

.. literalinclude:: JuniorDeveloper.php
   :language: php
   :linenos:

Test
----

Tests/DelegationTest.php

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

.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/Delegation
.. __: http://en.wikipedia.org/wiki/Delegation_pattern