Bird
0
0

Find the mistake in this Observer pattern usage: Observers modify the Subject's state directly upon notification.

medium📝 Analysis Q7 of 15
LLD - Behavioral Design Patterns — Part 2
Find the mistake in this Observer pattern usage: Observers modify the Subject's state directly upon notification.
AObservers must always modify Subject's state
BObservers should not modify Subject's state directly
CSubject should notify Observers only once
DObservers should poll Subject instead of receiving notifications
Step-by-Step Solution
Solution:
  1. Step 1: Understand Observer pattern roles

    Subject owns state; Observers react to changes but do not change Subject directly.
  2. Step 2: Identify correct behavior

    Observers should not modify Subject's state to avoid tight coupling and maintain separation of concerns.
  3. Final Answer:

    Observers should not modify Subject's state directly -> Option B
  4. Quick Check:

    Observer respects Subject's state ownership = A [OK]
Quick Trick: Observers react, don't modify Subject's state [OK]
Common Mistakes:
MISTAKES
  • Allowing observers to change Subject state
  • Confusing notification with polling
  • Assuming single notification is enough

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes