2017-04-03 19:14:10 -06:00
..
2017-03-09 00:35:08 +01:00
2014-07-31 14:47:55 -05:00
2016-09-22 11:45:38 +02:00
2016-09-22 11:45:38 +02:00
2016-09-22 11:45:38 +02:00
2016-09-22 11:45:38 +02:00

`State`__
=========

Purpose
-------

Encapsulate varying behavior for the same routine based on an object's
state. This can be a cleaner way for an object to change its behavior at
runtime without resorting to large monolithic conditional statements.

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

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

Code
----

You can also find this code on `GitHub`_

OrderRepository.php

.. literalinclude:: OrderRepository.php
   :language: php
   :linenos:

Order.php

.. literalinclude:: Order.php
   :language: php
   :linenos:

ShippingOrder.php

.. literalinclude:: ShippingOrder.php
   :language: php
   :linenos:

CreateOrder.php

.. literalinclude:: CreateOrder.php
   :language: php
   :linenos:

Test
----

.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/State
.. __: http://en.wikipedia.org/wiki/State_pattern