Skip to content

Latest commit

 

History

History
 
 

Decorator

Purpose

To dynamically add new functionality to class instances.

Examples

  • Zend Framework: decorators for Zend_Form_Element instances
  • Web Service Layer: Decorators JSON and XML for a REST service (in this case, only one of these should be allowed of course)

UML Diagram

Alt Decorator UML Diagram

Code

You can also find these code on GitHub

RendererInterface.php

.. literalinclude:: RendererInterface.php
   :language: php
   :linenos:

Webservice.php

.. literalinclude:: Webservice.php
   :language: php
   :linenos:

Decorator.php

.. literalinclude:: Decorator.php
   :language: php
   :linenos:

RenderInXml.php

.. literalinclude:: RenderInXml.php
   :language: php
   :linenos:

RenderInJson.php

.. literalinclude:: RenderInJson.php
   :language: php
   :linenos:

Test

Tests/DecoratorTest.php

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