Colleague (User):?
Short answer: The User class represents a user in the chat application.
Explain a bit more
Each user has a name and a reference to the mediator. When a user wants to send a message, they call Send() on the mediator, which then sends the message to all other registered users. Users only interact with the mediator, and not with each other directly. public class User public void Send(string message) => _mediator.SendMessage(message, this); public void Receive(string message) => Console.WriteLine($"{_name} received: {message}"); }
Example code
{
private readonly string _name;
private readonly IChatMediator _mediator;
public User(string name, IChatMediator mediator)
{
_name = name;
_mediator = mediator; _mediator.RegisterUser(this); // Register the user with the mediator }
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