Created
January 21, 2013 10:46
-
-
Save rowan-m/4585210 to your computer and use it in GitHub Desktop.
Trait for providing behaviour from the observer pattern.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Sorting; | |
trait ObservableTrait | |
{ | |
private $observers = array(); | |
public function addObserver(Observer $observer) | |
{ | |
$this->observers[] = $observer; | |
} | |
public function notifyObservers() | |
{ | |
foreach ($this->observers as $observer) { | |
$observer->notify($this); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And where is delete or detach method?