大话设计模式_中介者模式
来源:互联网 发布:软件著作权在线查询 编辑:程序博客网 时间:2024/05/16 04:22
以美国和伊拉克通话要通过联合国安全理事会来传递.
package com.wzs.design;/** * 大话设计模式--page262 中介者模式 * * @author Administrator * */public class MediatorPattern {public static void main(String[] args) {UnitedNationsSecurityCouncil unsc = new UnitedNationsSecurityCouncil();USA c1 = new USA(unsc);Iraq c2 = new Iraq(unsc);unsc.setColleague1(c1);unsc.setColleague2(c2);c1.declare("不准研制和武器,否则要发动战争!");c2.declare("我们没有核武器,也不怕侵略.");}}// 国家类abstract class Country {protected UnitedNations mediator;public Country(UnitedNations mediator) {this.mediator = mediator;}}// 美国class USA extends Country {public USA(UnitedNations mediator) {super(mediator);}public void declare(String message) {mediator.declare(message, this);}public void getMessage(String message) {System.out.println("美国获得对方信息:" + message);}}// 伊拉克class Iraq extends Country {public Iraq(UnitedNations mediator) {super(mediator);}public void declare(String message) {mediator.declare(message, this);}public void getMessage(String message) {System.out.println("伊拉克获得对方信息:" + message);}}// 联合国机构类abstract class UnitedNations {public abstract void declare(String message, Country colleague);}// 联合国安全理事会class UnitedNationsSecurityCouncil extends UnitedNations {private USA colleague1;private Iraq colleague2;// 美国public void setColleague1(USA colleague1) {this.colleague1 = colleague1;}// 伊拉克public void setColleague2(Iraq colleague2) {this.colleague2 = colleague2;}@Overridepublic void declare(String message, Country colleague) {if (colleague == colleague1) {colleague1.getMessage(message);} else {colleague2.getMessage(message);}}}
- 大话设计模式_中介者模式
- 大话设计模式-中介者模式
- 大话设计模式 中介者模式
- 大话设计模式之中介者模式
- 大话设计模式—中介者模式
- 大话设计模式-中介者模式
- 大话设计模式25----中介者模式
- 大话设计模式之中介者模式
- 大话设计模式_中介模式c++实现
- 大话设计—中介者模式
- 大话设计模式-----(十)职责链模式、中介者模式
- 设计模式_中介者模式
- java设计模式_中介者模式
- 设计模式_中介者模式下
- 设计模式_中介者模式(25)
- 大话设计模式二十五:中介者模式(mediator)
- 大话设计模式--中介者模式 Mediator --C++实现实例
- 大话设计模式读书笔记之中介者模式
- 多校联合 03 15 A
- 云计算应具备的九大特征
- HTML5音频
- android 基于socket的聊天室
- XHTML与CSS基础:(三)良好的XHTML编写习惯
- 大话设计模式_中介者模式
- Ruby on Rails(Ubuntu64位12.04)连接sql-server2005说明
- Nagios的安装
- vc++学习——源程序组成结构(No.2)
- Race conditions
- 超越自己
- php趋势和前景
- git的一些常用命令
- C++中String类与char array的区别