Design Patterns · Junior · Question 6 of 75
How does the Observer pattern work?
- ✓Correct answer: An object keeps subscribers and notifies them when its state changes
- 2An object periodically polls other objects for changes
- 3An object copies its state into all related objects at once
Explanation
The subject provides subscribe/unsubscribe and calls callbacks on change. Web examples: addEventListener, store subscriptions in Redux and Zustand, RxJS. The key thing is to remember to unsubscribe, otherwise you get memory leaks.