Bird
0
0

Identify the error in this Mediator pattern snippet: The mediator directly accesses private fields of components to send messages.

medium📝 Analysis Q6 of 15
LLD - Behavioral Design Patterns — Part 2
Identify the error in this Mediator pattern snippet: The mediator directly accesses private fields of components to send messages.
AMediator should broadcast messages to all components
BMediator must access private fields for efficiency
CComponents should not communicate via mediator
DMediator should use public methods, not access private fields
Step-by-Step Solution
Solution:
  1. Step 1: Understand encapsulation principle

    Private fields should not be accessed directly outside their class to maintain encapsulation.
  2. Step 2: Apply to Mediator pattern

    Mediator should communicate via public methods, not private fields, to respect encapsulation.
  3. Final Answer:

    Mediator should use public methods, not access private fields -> Option D
  4. Quick Check:

    Respect encapsulation in Mediator = A [OK]
Quick Trick: Mediator uses public interfaces, not private fields [OK]
Common Mistakes:
MISTAKES
  • Allowing mediator to access private fields
  • Thinking direct access improves efficiency
  • Ignoring encapsulation principles

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes