static void Main() { var mediator = new Mediator(); var firstColleague = new ColleagueA(mediator); var secondColleague = new ColleagueB(mediator); firstColleague.Send(); secondColleague.Receive(); mediator.SendMessage(firstColleague); }
static void Main(string[] args) { Console.WriteLine("Using structural code : "); Console.WriteLine(); Mediator mediator = new Mediator(); ColleagueA colleagueA = new ColleagueA(mediator); ColleagueB colleagueB = new ColleagueB(mediator); mediator.ColleagueA = colleagueA; mediator.ColleagueB = colleagueB; colleagueA.Send("Hi! I'm colleagueA"); colleagueB.Send("Hi! I'm colleagueB"); Console.ReadLine(); Console.WriteLine("Using real-world code : "); Console.WriteLine(); Console.ReadLine(); }
static void Main(string[] args) { ConcreteMediator mediator = new ConcreteMediator(); ColleagueA colleagueA = new ColleagueA(mediator); ColleagueB colleagueB = new ColleagueB(mediator); mediator.SetColleagueA(colleagueA); mediator.SetColleagueB(colleagueB); colleagueB.Send("Hello A"); colleagueA.Send("Hello B"); CustomerServericeMM customerMM = new CustomerServericeMM(); Customer customer = new Customer(customerMM); Techician techician = new Techician(customerMM); customerMM.SetCustomer(customer); customerMM.SetTechicain(techician); customer.Ask("客户提问"); techician.Answer("技术支持解答"); }