Concrete Mediator (ChatMediator):?
Short answer: The ChatMediator class is the concrete mediator that implements IChatMediator. It manages a list of users and is responsible for broadcasting messages to all registered users, except the one who sent the message. The mediator decouples the user objects from each other, so they don't need to know about each other's existence. public class ChatMediator : IChatMediator
Example code
{
private readonly List<User> _users = new List<User>();
public void RegisterUser(User user) => _users.Add(user);
public void SendMessage(string message, User user)
{
foreach (var u in _users)
{ // Message should not be sent to the user who sent it if (u != user)
{ u.Receive(message); }
}
}
}
Real-world example (ShopNest)
Use a GoF pattern in ShopNest only when it removes duplication or makes a change safer—explain the problem it solves in the interview.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png