Bird
0
0

You are designing a messaging system where multiple objects need to react to events from a central source without tight coupling. Which behavioral pattern best fits this requirement and why?

hard📝 Trade-off Q15 of 15
LLD - Behavioral Design Patterns — Part 1
You are designing a messaging system where multiple objects need to react to events from a central source without tight coupling. Which behavioral pattern best fits this requirement and why?
ADecorator pattern, because it adds responsibilities to message objects
BSingleton pattern, because it ensures only one instance handles all messages
CObserver pattern, because it allows objects to subscribe and get notified of changes
DFactory pattern, because it creates message objects dynamically
Step-by-Step Solution
Solution:
  1. Step 1: Identify the need for loose coupling and event notification

    The system requires multiple objects to react to events without tight connections, which means they should be able to subscribe and be notified.
  2. Step 2: Match pattern to requirement

    The Observer pattern fits perfectly as it allows objects to register as observers and get notified when the subject changes, promoting loose coupling.
  3. Final Answer:

    Observer pattern, because it allows objects to subscribe and get notified of changes -> Option C
  4. Quick Check:

    Loose coupling + notifications = Observer [OK]
Quick Trick: Observer = subscribe and notify for loose coupling [OK]
Common Mistakes:
MISTAKES
  • Choosing Singleton which limits to one instance
  • Confusing creation patterns with interaction patterns
  • Using Decorator which adds features, not notifications

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes