Behavioral/Strategy/README.rst
Strategy__To separate strategies and to enable fast switching between them. Also this pattern is a good alternative to inheritance (instead of having an abstract class that is extended).
.. image:: uml/uml.png :alt: Alt Strategy UML Diagram :align: center
You can also find this code on GitHub_
Context.php
.. literalinclude:: Context.php :language: php :linenos:
Comparator.php
.. literalinclude:: Comparator.php :language: php :linenos:
DateComparator.php
.. literalinclude:: DateComparator.php :language: php :linenos:
IdComparator.php
.. literalinclude:: IdComparator.php :language: php :linenos:
Tests/StrategyTest.php
.. literalinclude:: Tests/StrategyTest.php :language: php :linenos:
.. _GitHub: https://github.com/DesignPatternsPHP/DesignPatternsPHP/tree/main/Behavioral/Strategy
.. __: http://en.wikipedia.org/wiki/Strategy_pattern