Skip to content

Instantly share code, notes, and snippets.

@rowan-m
Created January 21, 2013 10:46
Show Gist options
  • Save rowan-m/4585210 to your computer and use it in GitHub Desktop.
Save rowan-m/4585210 to your computer and use it in GitHub Desktop.
Trait for providing behaviour from the observer pattern.
<?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);
}
}
}
@seyfer
Copy link

seyfer commented Dec 2, 2013

And where is delete or detach method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment