Bird
0
0

In a Mediator pattern, if Component X sends a message 'Update' intended for Component Y, what is the expected behavior of the mediator?

medium📝 Analysis Q4 of 15
LLD - Behavioral Design Patterns — Part 2
In a Mediator pattern, if Component X sends a message 'Update' intended for Component Y, what is the expected behavior of the mediator?
AComponent X sends the message directly to Component Y bypassing the mediator.
BThe mediator forwards the 'Update' message to Component Y without components communicating directly.
CThe mediator modifies the message and sends it to all components including X and Y.
DComponent Y polls the mediator periodically to receive messages from Component X.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Mediator Role

    The mediator centralizes communication between components to reduce direct dependencies.
  2. Step 2: Message Forwarding

    When Component X sends 'Update', the mediator forwards it only to the intended recipient, Component Y.
  3. Final Answer:

    The mediator forwards the 'Update' message to Component Y without components communicating directly. -> Option B
  4. Quick Check:

    Direct communication is avoided in Mediator pattern [OK]
Quick Trick: Mediator centralizes communication, forwarding messages correctly [OK]
Common Mistakes:
MISTAKES
  • Assuming components communicate directly
  • Mediator broadcasting to all components unnecessarily
  • Components polling mediator instead of mediator pushing messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes