//中介者模式和之前写过的观察者模式很相似,均属于行为型模式 //观察者模式中观察者与被观察者(也叫主题),通常是多对一的关系 //一个主题被多个观察者观察,观察是单方面的 //中介者模式中,注册到中介者的各个类不直接联系,通过中介转发,呈现出多对多的关系 //注册到中介的各个类,既可以发送通知也可以接收通知 static void Main(string[] args) { IMediator mediator = new ConcreteMediator(); WorkMate wm1 = new ConcreteMate1(); WorkMate wm2 = new ConcreteMate2(); mediator.register(wm1); mediator.register(wm2); wm1.send("今天老板要请大家吃麻辣烫"); wm2.send("明天老板娘要请大家吃小龙虾"); Console.Read(); }