June 2017
Intermediate to advanced
536 pages
9h 49m
English
The observer pattern is quite a popular one. It allows for an event subscription type of behavior. We differentiate the subject and observer(s) type of objects. The observer is an object subscribed to subject object state change. When the subject changes its state, it notifies all of its observers automatically.
The following example demonstrates a possible observer pattern implementation:
<?phpclass CheckoutSuccess implements \SplSubject{ protected $salesOrder; protected $observers; public function __construct($salesOrder) { $this->salesOrder = $salesOrder; $this->observers = new \SplObjectStorage(); } public function attach(\SplObserver $observer) { $this->observers->attach($observer); } public function detach(\SplObserver ...