Bird
0
0
LLDsystem_design~10 mins

Mediator pattern in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the Mediator interface method for communication.

LLD
interface Mediator {
    void [1](String message, Colleague colleague);
}
Drag options to blanks, or click blank then click option'
Abroadcast
BreceiveMessage
CsendMessage
DnotifyAll
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'receiveMessage' instead of 'sendMessage'.
Using 'notifyAll' which is a Java Object method, not part of Mediator.
2fill in blank
medium

Complete the code to implement the colleague's method to send a message via the mediator.

LLD
class ConcreteColleague extends Colleague {
    void send(String message) {
        mediator.[1](message, this);
    }
}
Drag options to blanks, or click blank then click option'
AsendMessage
BreceiveMessage
Cnotify
DbroadcastMessage
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a method named 'receiveMessage' on the mediator.
Using 'notify' which is unrelated here.
3fill in blank
hard

Fix the error in the mediator's notify method to correctly notify all colleagues except the sender.

LLD
void notifyColleagues(String message, Colleague sender) {
    for (Colleague colleague : colleagues) {
        if (colleague != [1]) {
            colleague.receive(message);
        }
    }
}
Drag options to blanks, or click blank then click option'
Athis
Bsender
Cnull
Dcolleague
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'this' which refers to the mediator itself.
Using 'colleague' which is the loop variable.
4fill in blank
hard

Fill both blanks to define a colleague class constructor and store the mediator reference.

LLD
class ConcreteColleague extends Colleague {
    ConcreteColleague(Mediator [1]) {
        this.[2] = [1];
    }
}
Drag options to blanks, or click blank then click option'
Amediator
Bcolleague
CmediatorRef
Dsender
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for parameter and instance variable causing confusion.
Using unrelated names like 'colleague' or 'sender'.
5fill in blank
hard

Fill all three blanks to implement the mediator's sendMessage method that forwards messages to all colleagues except the sender.

LLD
void [1](String message, Colleague sender) {
    for (Colleague [2] : colleagues) {
        if ([2] != sender) {
            [2].receive(message);
        }
    }
}
Drag options to blanks, or click blank then click option'
AsendMessage
Bcolleague
Cnotify
Dbroadcast
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using incorrect method names like 'notify' or 'broadcast'.