Colleague (User):?
- The User class represents a user in the chat application. 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
{
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
}
public void Send(string message) =>
_mediator.SendMessage(message, this);
public void Receive(string message) =>
Console.WriteLine($"{_name} received: {message}");
}