Observer: Introduction
Get a brief introduction to the Observer design pattern.
We'll cover the following
The Observer design pattern facilitates communication between objects via publication and subscription models. When using this pattern, objects can subscribe to each other, so that they get notified when specific events are triggered. They can also unsubscribe from each other at any point.
Summarized concepts of the Observer design pattern
The Observer design pattern can be summarized as follows:
- Subject or Publisher is an object that emits some events.
- An Observer or Subscriber is an object that can subscribe to the Subject, so it can receive notifications when a specific event occurs.
- The Subject object exposes methods that allow Observer objects to subscribe to or unsubscribe from it.
- The Subject object maintains an internal list of all Observer objects that are subscribed to it.
Get hands-on with 1400+ tech skills courses.