Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.03 KB

README.rst

File metadata and controls

58 lines (40 loc) · 1.03 KB

Purpose

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.

Examples

  • a message queue system is observed to show the progress of a job in a GUI

Note

PHP already defines two interfaces that can help to implement this pattern: SplObserver and SplSubject.

UML Diagram

Alt Observer UML Diagram

Code

You can also find this code on GitHub

User.php

User.php

UserObserver.php

UserObserver.php

Test

Tests/ObserverTest.php

Tests/ObserverTest.php