Mediator Pattern — Concept Check
Questions on Mediator Pattern. Defines an object that encapsulates how a set of objects interact, promoting loose coupling by preventing direct references between them.
Questions in this quiz
8 questions on Mediator Pattern — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.In a chat application using the Mediator pattern, Alice sends a message to Bob, but Bob doesn't receive it. What could be a possible reason?
- AThe ChatRoom mediator is overloaded.
- BAlice doesn't have Bob's direct reference.
- CAlice sent the message to the wrong user ID.
- DBob is not registered with the ChatRoom mediator.
2.A developer claims that using a Mediator pattern in a chat application will completely eliminate coupling between objects. What is the flaw in this statement?
- AObjects still need to reference the mediator.
- BThe mediator can only handle broadcast messages.
- CThe mediator itself becomes a central point of coupling.
- DThe mediator pattern doesn't support direct messaging.
3.In a chat room using the Mediator pattern, what happens if the ChatRoom mediator becomes too complex?
- AIt can turn into a 'god object', making maintenance difficult.
- BIt will automatically handle all message routing efficiently.
- CIt will reduce the performance of the entire application.
- DUsers will be unable to send direct messages.
4.A user in a chat application using the Mediator pattern complains that they receive messages from unknown users. What is a likely cause?
- AThe mediator allows broadcast messages to all users.
- BThe user is not registered correctly with the mediator.
- CThe mediator is incorrectly routing messages.
- DThe sender's ID is not verified by the mediator.
5.What is a potential downside of using the Mediator pattern in a chat application?
- AUsers cannot send messages directly to each other.
- BIt requires all users to have direct references to each other.
- CThe pattern increases the number of dependencies between objects.
- DThe mediator can become overly complex and difficult to manage.
6.In the ChatRoom example, why do users not hold references to each other?
- ATo allow the mediator to handle user authentication.
- BTo reduce coupling between users by using the mediator for communication.
- CTo prevent users from sending messages directly to each other.
- DTo ensure that all messages are broadcasted to every user.
7.What is the role of the ChatRoom mediator in the provided code example?
- AIt handles user authentication and authorization.
- BIt directly connects users for message exchange.
- CIt registers users and routes messages between them.
- DIt stores all messages sent in the chat room.
8.A developer wants to add a feature to log all messages sent in the chat application using the Mediator pattern. Where should this functionality be implemented?
- AIn the ChatRoom mediator, to centralize logging.
- BIn a separate logging service, to keep concerns separate.
- CIn the sendMessage method of the User class.
- DIn each User object, to log messages individually.