Bird
0
0

Find the bug in this Mediator usage:

medium📝 Analysis Q7 of 15
LLD - Behavioral Design Patterns — Part 2
Find the bug in this Mediator usage:
class Mediator {
  notify(sender, event) {
    if (event === 'click') {
      console.log(sender + ' clicked');
    }
  }
}
const mediator = new Mediator();
mediator.notify('Button');
Anotify method should not use console.log
Bnotify called with missing event argument
CMediator class should be abstract
DNo bug, code works fine
Step-by-Step Solution
Solution:
  1. Step 1: Check notify method parameters

    Notify expects two parameters: sender and event.
  2. Step 2: Analyze method call

    Called with only one argument, missing event parameter causes undefined behavior.
  3. Final Answer:

    notify called with missing event argument -> Option B
  4. Quick Check:

    Missing event argument causes bug [OK]
Quick Trick: Always pass sender and event to notify [OK]
Common Mistakes:
MISTAKES
  • Thinking console.log is wrong
  • Assuming Mediator must be abstract
  • Believing code runs without error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes