public void TestMethod1() { var mediator = new ConcreteMediator(); var colleague1 = new ConcreteColleague(mediator); var colleague2 = new ConcreteColleague(mediator); mediator.AddColleague(colleague1); mediator.AddColleague(colleague2); colleague1.Send("form C1"); colleague2.Send("from C2"); }
public void MediatorTest() { ConcreteMediator concreteMediator = new ConcreteMediator(); Action <Intent> action = x => _logger.Debug("mediator", x.EventMessage); concreteMediator.AddColleague("testA", new ColleagueDelegate(action)); concreteMediator.AddColleague("testB", new ColleagueDelegate(action)); concreteMediator.Trigger("testA", "test"); concreteMediator.Execute(new Intent("aaaaaaaaaaa")); }
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); }
private void Start() { ConcreteMediator m = new ConcreteMediator(); ConcreteColleague1 c1 = new ConcreteColleague1(m); ConcreteColleague2 c2 = new ConcreteColleague2(m); ConcreteColleague c3 = new ConcreteColleague(m); ConcreteColleague c4 = new ConcreteColleague(m); ConcreteColleague c5 = new ConcreteColleague(m); ConcreteColleague c6 = new ConcreteColleague(m); ConcreteColleague c7 = new ConcreteColleague(m); //m.Colleague1 = c1; //m.Colleague2 = c2; m.AddColleague(c1); m.AddColleague(c2); m.AddColleague(c3); m.AddColleague(c4); m.AddColleague(c5); m.AddColleague(c6); m.AddColleague(c7); c1.Send("How are you?"); c2.Send("Fine, thanks"); }