Bird
Raised Fist0

How can you extend the Observer pattern to support observers that only want updates for specific types of changes?

hard📝 Trade-off Q9 of Q15
LLD - Behavioral Design Patterns — Part 1

How can you extend the Observer pattern to support observers that only want updates for specific types of changes?

AMake all observers receive all updates and filter internally
BUse multiple Subjects for each change type without filtering
CRemove observers frequently to control notifications
DAdd filtering logic in Subject to notify only relevant observers
Step-by-Step Solution
Solution:
  1. Step 1: Understand selective notification need

    Observers want updates only for certain change types.
  2. Step 2: Implement filtering in Subject

    Subject can track observer interests and notify selectively.
  3. Final Answer:

    Add filtering logic in Subject to notify only relevant observers -> Option D
  4. Quick Check:

    Selective notify requires filtering in Subject [OK]
Quick Trick: Filter notifications in Subject for selective updates [OK]
Common Mistakes:
MISTAKES
  • Letting observers filter all updates wastes resources
  • Removing observers to control notifications is inefficient
  • Using multiple Subjects complicates design unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes