static void Main(string[] args) { UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil(); USA c1 = new USA(UNSC); Iraq c2 = new Iraq(UNSC); UNSC.Colleague1 = c1; UNSC.Colleague2 = c2; c1.Declare("不准研制核武器,否则要发动战争!"); c2.Declare("我们没有核武器,也不怕侵略。"); Console.Read(); }
static void Main(string[] args) { //实例化 具体中介者 联合国安理会 UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil(); //实例化一个美国 USA c1 = new USA(UNSC); //实例化一个里拉开 Iraq c2 = new Iraq(UNSC); //将两个对象赋值给安理会 //具体的中介者必须知道全部的对象 UNSC.Colleague1 = c1; UNSC.Colleague2 = c2; //美国发表声明,伊拉克接收到 c1.Declare("不准研制核武器,否则要发动战争!"); //伊拉克发表声明,美国收到信息 c2.Declare("我们没有核武器,也不怕侵略。"); Console.Read(); }
static void Main(string[] args) { ConcreteMediator m = new ConcreteMediator(); ConcreteColleague1 c1 = new ConcreteColleague1(m); ConcreteColleague2 c2 = new ConcreteColleague2(m); m.Colleage1 = c1; m.Colleage2 = c2; c1.Send("吃过饭了吗?"); c2.Send("没有呢,你打算请客?"); UnitedNationsSecurityCouncil unsc = new UnitedNationsSecurityCouncil(); USA usa = new USA(unsc); Iraq iraq = new Iraq(unsc); unsc.Usa = usa; unsc.Iraq = iraq; usa.Declare("不准研制核武器,否则要发动战争"); iraq.Declare("我们没有核武器,也不怕侵略"); }