Bird
0
0

You need to design a notification system that supports multiple types of state changes and notifies observers only for the types they subscribed to. Which design approach is best?

hard📝 Trade-off Q8 of 15
LLD - Design — Online Shopping Cart
You need to design a notification system that supports multiple types of state changes and notifies observers only for the types they subscribed to. Which design approach is best?
AUse a Singleton pattern to manage all notifications globally.
BUse a Decorator pattern to add notification behavior dynamically.
CUse a Factory pattern to create different observer objects.
DUse the Observer pattern with event types and filter notifications by type.
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement for event filtering

    Observers want notifications only for specific state change types, so filtering is needed.
  2. Step 2: Match design pattern to filtering need

    Observer pattern extended with event types allows selective notification, fitting the requirement best.
  3. Final Answer:

    Use the Observer pattern with event types and filter notifications by type. -> Option D
  4. Quick Check:

    Selective notify = Observer with event filtering [OK]
Quick Trick: Add event types to Observer pattern for selective notify [OK]
Common Mistakes:
  • Choosing Singleton which lacks filtering
  • Using Factory which only creates objects
  • Applying Decorator which adds behavior but not filtering

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes