Bird
Raised Fist0

Given the following snapshot of the observer registry in a thread-safe observer pattern implementation: ```python observers = { 'eventA': {obs1, obs3}, 'eventB': {obs2} } ``` If a notify call for 'eventA' results in only obs3 receiving the update, which of the following is the most likely cause?

hard🔄 Reverse Engineer Q9 of Q15
OOP & Design Patterns - Observer Pattern - Event System, Publish-Subscribe
Given the following snapshot of the observer registry in a thread-safe observer pattern implementation: ```python observers = { 'eventA': {obs1, obs3}, 'eventB': {obs2} } ``` If a notify call for 'eventA' results in only obs3 receiving the update, which of the following is the most likely cause?
Aobs1 unsubscribed from 'eventA' but the registry was not updated
Bobs1's update method is overridden to ignore notifications
CThe notify method incorrectly filters observers by event type
Dobs3 is subscribed to multiple event types and receives all notifications
Step-by-Step Solution
Solution:
  1. Step 1: Analyze observer registry

    Both obs1 and obs3 are subscribed to 'eventA'.
  2. Step 2: Consider notify behavior

    Notify calls update on all subscribed observers; if only obs3 receives update, obs1 must be ignoring or suppressing updates.
  3. Step 3: Eliminate other causes

    Registry shows obs1 subscribed, so unsubscribe not done; notify filters correctly; obs3's multiple subscriptions irrelevant.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Observer's update method can suppress notifications [OK]
Quick Trick: Subscribed observer may ignore updates internally [OK]
Common Mistakes:
MISTAKES
  • Assuming unsubscribe not done
  • Blaming notify filtering
  • Ignoring observer internal logic
Trap Explanation:
PITFALL
  • Candidates often assume registry state matches notification, ignoring observer internal behavior.
Interviewer Note:
CONTEXT
  • Tests deep understanding of observer notification flow and internal observer behavior.
Master "Observer Pattern - Event System, Publish-Subscribe" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes