public static void Main(string[] args) { MediatorA mediator = new MediatorA(); ColleagueA colleagueA = new ColleagueA(mediator); ColleagueB colleagueB = new ColleagueB(mediator); mediator.AddColleague(colleagueA); mediator.AddColleague(colleagueB); colleagueA.Mediate(); colleagueB.Mediate(); }
public void MediatorPattern_Test() { ColleagueA colleagueA = new ColleagueA(); ColleagueB colleagueB = new ColleagueB(); Mediator mediatorA = new MediatorA(colleagueA, colleagueB); colleagueA.SetMediator(mediatorA); colleagueB.SetMediator(mediatorA); var resultA = colleagueA.NotifyColleagueB(); var resultB = colleagueB.NotifyColleagueA(); Assert.Equal("MediatorA ColleagueB Notify", resultA); Assert.Equal("MediatorA ColleagueA Notify", resultB); }