行为型模式-中介者mediator
来源:互联网 发布:淘宝商城质检报告 编辑:程序博客网 时间:2024/06/01 07:22
using System;using System.Collections.Generic;using System.Text;namespace 中介者模式{ class Program { 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(); } } //联合国机构 abstract class UnitedNations { /// <summary> /// 声明 /// </summary> /// <param name="message">声明信息</param> /// <param name="colleague">声明国家</param> public abstract void Declare(string message, Country colleague); } //联合国安全理事会 class UnitedNationsSecurityCouncil : UnitedNations { private USA colleague1; private Iraq colleague2; public USA Colleague1 { set { colleague1 = value; } } public Iraq Colleague2 { set { colleague2 = value; } } public override void Declare(string message, Country colleague) { if (colleague == colleague1) { colleague2.GetMessage(message); } else { colleague1.GetMessage(message); } } } //国家 abstract class Country { protected UnitedNations mediator; public Country(UnitedNations mediator) { this.mediator = mediator; } } //美国 class USA : Country { public USA(UnitedNations mediator) : base(mediator) { } //声明 public void Declare(string message) { mediator.Declare(message, this); } //获得消息 public void GetMessage(string message) { Console.WriteLine("美国获得对方信息:" + message); } } //伊拉克 class Iraq : Country { public Iraq(UnitedNations mediator) : base(mediator) { } //声明 public void Declare(string message) { mediator.Declare(message, this); } //获得消息 public void GetMessage(string message) { Console.WriteLine("伊拉克获得对方信息:" + message); } }}
0 0
- 行为型模式-Mediator ( 中介者模式 )
- Mediator中介者(行为型设计模式)
- 行为型模式-中介者mediator
- 行为型模式之中介者MEDIATOR
- 行为型模式-中介者(mediator)
- 行为型-中介者模式(Mediator)
- 设计模式(17)-行为型-中介者模式(Mediator)
- 行为型模式-----中介者模式(Mediator)
- 设计模式--中介者模式Mediator(行为型)
- [设计模式-行为型]中介者模式(Mediator)
- 设计模式(行为型)之中介者模式(Mediator Pattern)
- 六、中介者模式Mediator(行为型模式)
- 设计模式-行为型-中介者模式(Mediator)
- 行为型模式之中介者模式(Mediator)
- 中介者模式(Mediator)(对象行为型模式)
- Mediator 中介者模式 --对象行为型模式
- 行为设计模式---中介者模式(Mediator)
- 中介者(Mediator)----对象行为型模式
- Js-Html 前端系列--显示有格式的文本
- 行为型模式-迭代器interator
- Java反射:边看书边总结
- swift基础(三)函数定义
- 即使被拖库,也可以保证密码不泄露
- 行为型模式-中介者mediator
- 行为型模式-备忘录memento
- operator new, new operator, delete new, new delete
- 行为型模式-观察者observer
- 解决Codeforces访问慢的本地方法
- PPAPI插件的绘图与输入事件处理
- IOS-IOS应用的核心(一)
- 【杭电oj】1215 - 七夕节(打表,水)
- 归档,解档