Behavioral/Observer/README.rst
Observer__To implement a publish/subscribe behaviour to an object, whenever a "Subject" object changes its state, the attached "Observers" will be notified. It is used to shorten the amount of coupled objects and uses loose coupling instead.
PHP already defines two interfaces that can help to implement this pattern: SplObserver and SplSubject.
.. image:: uml/uml.png :alt: Alt Observer UML Diagram :align: center
You can also find this code on GitHub_
User.php
.. literalinclude:: User.php :language: php :linenos:
UserObserver.php
.. literalinclude:: UserObserver.php :language: php :linenos:
Tests/ObserverTest.php
.. literalinclude:: Tests/ObserverTest.php :language: php :linenos:
.. _GitHub: https://github.com/DesignPatternsPHP/DesignPatternsPHP/tree/main/Behavioral/Observer
.. __: http://en.wikipedia.org/wiki/Observer_pattern