-
Book Overview & Buying
-
Table Of Contents
TypeScript 5 Design Patterns and Best Practices - Second Edition
By :
The Observer pattern is a behavioral design pattern that implements a system for objects to post events and other objects to subscribe to those events and act accordingly. This pattern is also known as the publish-subscribe pattern.
At its core, the Observer pattern consists of two main components:
As an analogy, think of a newspaper subscription service: The newspaper company (subject) maintains a list of subscribers (observers). When a new edition is published, all subscribers are automatically notified, and subscribers can join or leave the subscription list at any time.
The Observer pattern is particularly useful in scenarios where you want to avoid direct calls between subsystems that should not know each other’s existence...