Bird
Raised Fist0

In the Observer pattern, what is the main responsibility of the Subject?

easy🧠 Conceptual Q2 of Q15
LLD - Behavioral Design Patterns — Part 1

In the Observer pattern, what is the main responsibility of the Subject?

ATo update the observers' internal state
BTo notify all registered observers about state changes
CTo unregister itself from observers
DTo create new observers
Step-by-Step Solution
Solution:
  1. Step 1: Identify Subject's role

    The Subject holds the state and manages observers.
  2. Step 2: Understand notification responsibility

    When the Subject's state changes, it must notify all registered observers.
  3. Final Answer:

    To notify all registered observers about state changes -> Option B
  4. Quick Check:

    Subject responsibility = Notify observers [OK]
Quick Trick: Subject tells observers when state changes [OK]
Common Mistakes:
MISTAKES
  • Thinking Subject updates observers' internal data
  • Confusing unregistering with notification
  • Assuming Subject creates observers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes