Observer
About
Similar to Mediator, but only ONE Object can be the publisher.
Allow many Objects (Subscribers) to subscribe to events that are broadcasted by an Object (Publisher).
Publisher
The class that will notify the Subscribers.
class Publisher {
subscribers: Subscriber[];
subscribe(Subscriber subscriber): void {
this.subcribers.push(subscriber);
};
unsubscribe(Subscriber subscriber): void {
this.subscribers.pop(subscriber);
};
notify(): void {
for (let subscriber of this.subscribers) doSomething();
};
}Subscriber
The interface or class of objects that will get notified.
Last updated