โ CS Visual Lab ยท Design Patterns
๐ Observer
๐ก The ideaOne object (the subject) keeps a list of observers and notifies all of them when it changes. The basis of events, listeners and pub/sub.
๐ In real lifeA YouTube channel (subject) and its subscribers (observers): a new video notifies every subscriber.
๐ฌ Watch it work
Step 1 of 4
Subscribe
SubjectObserver AObserver B
Observers register with the subject.
subject.subscribe(a); subject.subscribe(b);