static void Main(string[] args) { ApplicationMediator mediator = new ApplicationMediator(); ConcreteColleague desktop = new ConcreteColleague(mediator); MobileColleague mobile = new MobileColleague(mediator); mediator.addColleague(desktop); mediator.addColleague(mobile); desktop.send("Hello World"); mobile.send("Hello"); Console.ReadKey(); }
static void Main(string[] args) { IMediator mediator = new MessageMediator(); int numberOfColleagues = 10; List <IColleague> colleagues = new List <IColleague>(); for (int i = 0; i < numberOfColleagues; i++) { IColleague colleague = new ConcreteColleague($"Colleague-{i + 1}"); mediator.RegisterColleague(colleague); colleagues.Add(colleague); } var random = new Random(); var senderIndex = random.Next(0, colleagues.Count); var sender = colleagues[senderIndex] as ConcreteColleague; sender.SendMessage("Test", Guid.NewGuid().ToString()); Console.ReadKey(); }
static void Main(string[] args) { //list of participants IColleague <string> mark = new ConcreteColleague <string>("Mark"); IColleague <string> cj = new ConcreteColleague <string>("CJ"); IColleague <string> paul = new ConcreteColleague <string>("Paul"); IColleague <string> geno = new ConcreteColleague <string>("Geno"); IColleague <string> tessa = new ConcreteColleague <string>("Tessa"); IColleague <int> account1 = new ConcreteColleague <int>("Kris Account"); IColleague <int> account2 = new ConcreteColleague <int>("Joel Account"); IColleague <int> account3 = new ConcreteColleague <int>("Ronald Account"); Console.WriteLine("\n-- CHAT ROOM --"); IMediator <string> chatRoom1 = new ConcreteMediator <string>(); //participants registers to the mediator chatRoom1.Register(mark); chatRoom1.Register(cj); chatRoom1.Register(paul); chatRoom1.Register(tessa); //participantA sends out a message mark.SendMessage(chatRoom1, "message from MARK in chatroom 1!"); Console.WriteLine("\n-- MONEY TRANSFER --"); IMediator <int> PaymentGateway = new ConcreteMediator <int>(); //participants registers to the mediator PaymentGateway.Register(account1); PaymentGateway.Register(account2); PaymentGateway.Register(account3); //participantB sends out a message account1.SendMessage(PaymentGateway, 999); Console.ReadKey(); }