public void Show() { var cm = new ConcreteMediator(); var c1 = new ConcreteColleagueA(cm); var c2 = new ConcreteColleagueB(cm); cm.concreteColleagueA = c1; cm.concreteColleagueB = c2; c1.Send("`send` of ConcreteColleagueA is being called!"); c2.Send("`send` of ConcreteColleagueB is being called!"); }
public void MediatorPatternCodeTest() { ConcreteMediator mediator = new ConcreteMediator(); ConcreteColleagueA colleagueA = new ConcreteColleagueA(1, mediator); ConcreteColleagueB colleagueB = new ConcreteColleagueB(2, mediator); mediator.AddColleague(colleagueA); mediator.AddColleague(colleagueB); colleagueA.Send("你好", colleagueB); colleagueB.Send("hi", colleagueA); }