Skip to content

Observer Pattern

The Observer pattern allows objects to subscribe to events.

class Subject {
private array $observers = [];
public function attach($observer) {
$this->observers[] = $observer;
}
public function notify() {
foreach ($this->observers as $observer) {
$observer->update();
}
}
}