← All Quizzes
What is the Observer pattern and where is it commonly used?
Explanation
The Observer pattern is a behavioral design pattern where an object (subject/observable) maintains a list of dependents (observers) and notifies them of state changes. It enables pub/sub communication without tight coupling. Common uses: event systems in browsers (addEventListener), reactive programming (RxJS, React's useState), MVC frameworks (model changes notify views), and message queues. Modern implementations often use signals, observables, or event emitters. The pattern enables one-to-many relationships and loose coupling between event sources and handlers.