Complete the code to define the Mediator interface method for communication.
interface Mediator {
void [1](String message, Colleague colleague);
}The Mediator interface typically defines a method like sendMessage to facilitate communication between colleagues.
Complete the code to implement the colleague's method to send a message via the mediator.
class ConcreteColleague extends Colleague { void send(String message) { mediator.[1](message, this); } }
The colleague uses the mediator's sendMessage method to send messages.
Fix the error in the mediator's notify method to correctly notify all colleagues except the sender.
void notifyColleagues(String message, Colleague sender) {
for (Colleague colleague : colleagues) {
if (colleague != [1]) {
colleague.receive(message);
}
}
}The mediator should skip notifying the sender, so it compares with the sender parameter.
Fill both blanks to define a colleague class constructor and store the mediator reference.
class ConcreteColleague extends Colleague { ConcreteColleague(Mediator [1]) { this.[2] = [1]; } }
The constructor parameter and the instance variable are both commonly named mediator to hold the mediator reference.
Fill all three blanks to implement the mediator's sendMessage method that forwards messages to all colleagues except the sender.
void [1](String message, Colleague sender) { for (Colleague [2] : colleagues) { if ([2] != sender) { [2].receive(message); } } }
The method name is sendMessage. The loop variable is colleague, used twice to check and call receive.
