- 浏览: 602032 次
- 性别:
- 来自: 卡哇伊
文章分类
- 全部博客 (299)
- C# (25)
- Java (1)
- WinForm (0)
- Asp.Net (86)
- Jsp (2)
- Php (1)
- Web Service (0)
- Desgin Patterns (19)
- Data Structure & Algorithms (1)
- SQLserver (41)
- Mysql (0)
- Oracle (2)
- Javascript (50)
- Ajax (10)
- Jquery (1)
- Flex (0)
- Regular Expression (5)
- DIV+CSS+XHTML+XML (18)
- Software Test (0)
- Linux (0)
- Utility (17)
- Net Digest (4)
- windows 2003 (10)
- Other (4)
- English (1)
- IT Term (1)
最新评论
-
w497480098h:
学习了 很好谢谢
SQL Server下无限多级别分类查询解决办法(简单查询树形结构数据库表) -
main_fun:
确实不错
iframe自适应高度 -
jveqi:
...
DBA -
mxcie:
其它版本没有确认,今天使用vs2003时,其.sln文件也需要 ...
彻底删除项目的VSS源代码管理信息 -
moneyprosper:
就只有IE支持,火狐和谷歌都不支持此种方法。正在寻找中。。。
从父页面读取和操作iframe中内容方法
意图
用一个中介对象封装一系列的对象交互.中介者使各对象不需要显式地相互引用,从而使得其耦合松散,而且可以独立地改变他们之间的交互.
比如:有两个人,张三,李四,它们交互非常频繁,那么这两个对象之间耦合性比较强,那么改其中一个对象会对另一个对象产生直接的影响,如果在张三和李四之间加了另外一个中介者,张三和李四之间的交互完全通过中介者来传递,假设张三向和李四说一句话,那么张三就和中介者去说这句话,接着中介者把这句话传到李四这一边,同样李四也是重复这样一个过程.总之中介者是连接各个对象中介的一个角色,也就是说各个对象交互要通过中介者来进行交互,不能互相直接的进行交互.
适用性
1.一组对象以定义良好,但是复杂的方式进行通信.产生的相互依赖关系结构混乱且难以理解.
2.一个对象引用其他很多对象并且直接与这些对象通信,导致难以复用该对象.
3.想定制一个分部在多个类中的行为,而又不想生成太多的子类.
构成:
1.抽象中介者(Mediator):定义一个接口用于各同事对象(Colleague)之间通信.
2.具体中介者(ConcreteMediator):协调各个同事对象实现协作的行为,掌握并且维护它的各个同事对象的引用.
3.同事类(Colleague):每一个同事类对象都引用一个中介者对象,每一个同事对象在需要和其他同事对象通信时,就与它的中介者通信.
ClassDiagram:
SequenceDiagram:
//聊天室示例 class Client { static void Main(string[] args) { ChatRoom c = new ChatRoom(); Participant zhangsan = new ConcreteParticipantA("zhangsan"); Participant lisi = new ConcreteParticipantB("lisi"); Participant wangwu = new ConcreteParticipantA("wangwu"); c.Register(zhangsan); c.Register(lisi); c.Register(wangwu); zhangsan.Send("lisi","hello"); lisi.Send("wangwu","world"); wangwu.Send("zhangsan","helloworld"); Console.ReadKey(); } } /// <summary> /// 抽象中介者类 /// </summary> interface IChatRoom { void Register(Participant participant); void Send(string from, string to, string message); } /// <summary> /// 具体中介者---聊天室类 /// </summary> class ChatRoom : IChatRoom { private Hashtable participants = new Hashtable(); public void Register(Participant participant) { if (participants[participant.Name] == null) { participants[participant.Name] = participant; } participant.ChatRoom = this; } public void Send(String from, string to, string message) { Participant participant = participants[to] as Participant; if (null != participant) { participant.Receive(from, message); } } } /// <summary> /// 抽象同事类(AbstractColleague) /// </summary> abstract class Participant { private ChatRoom chatRoom; private string name; public Participant(string name) { this.name = name; } internal ChatRoom ChatRoom { get { return chatRoom; } set { chatRoom = value; } } public string Name { get { return name; } set { name = value; } } public void Send(string to, string message) { //调用中介者对象相应的Send方法. chatRoom.Send(name, to, message); } public virtual void Receive(string from, string message) { Console.WriteLine("{0} to {1}:{2}", from, name, message); } } /// <summary> /// 具体的同事类(ConcreteColleagueA) /// </summary> class ConcreteParticipantA : Participant { public ConcreteParticipantA(string name) : base(name) { } public override void Receive(string from, string message) { Console.WriteLine("To:" + this.GetType().Name); base.Receive(from, message); } } /// <summary> /// 具体的同事类(ConcreteColleagueB) /// </summary> class ConcreteParticipantB : Participant { public ConcreteParticipantB(string name) : base(name) { } public override void Receive(string from, string message) { Console.WriteLine("To: " + this.GetType().Name); base.Receive(from, message); } }
发表评论
-
AbstractFactoryPattern(二)
2009-05-01 21:42 678关于抽象工厂(Abstract F ... -
VisitorPattern
2009-05-01 19:20 806意图表示一个作用于某 ... -
MementoPattern
2009-05-01 16:10 691意图在不破坏封装性的前提下,捕获一个对象内部状态,并在该对象之 ... -
Statepattern
2009-04-30 13:45 765意图允许一个对象在其 ... -
Chain of Responsibility Pattern
2009-04-28 23:23 836意图使多个对象都有机会处理请求,从而避免请求的发送者和接收者之 ... -
InterpreterPattern
2009-04-28 14:43 830意图给定一个语言之后,解释器模式可以定义出其文法的一种表示,并 ... -
IteratorPattern
2009-04-26 18:15 792意图提供一种方法顺序 ... -
CommandPattern
2009-04-26 13:35 671意图:将一个请求封装为 ... -
StrategyPattern
2009-04-25 19:08 717策略模式(Strategy Pattern) 中体现了两个非常 ... -
TemplateMethodPattern
2009-04-25 13:24 808TemplateMethodPattern:定义一个操作中算法 ... -
PrototypePattern
2009-04-23 15:46 769意图用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的 ... -
追MM与23种设计模式
2009-04-21 15:13 6691、FACTORY—追MM少不了请 ... -
AbstractFactoryPattern
2009-04-21 13:23 719意图 提供一个创建一系列相关或相互依赖对象的接口,而无需指定 ... -
FactoryMethodPattern
2009-04-19 22:20 835工厂方法(FactoryMethod ... -
ObserverPattern
2009-03-27 17:40 770观察者模式又叫做发布- ... -
SimpleFactoryPattern
2009-03-26 00:57 770工厂模式专门负责将大量有共同接口的类实例化。工厂模式可以动态决 ... -
Builder Pattern
2009-03-21 18:47 1379建造者(Builder)模式 ... -
Singleton Pattern
2009-03-16 16:50 959单件模式:(Singleton pattern) 1.目的 1 ...
相关推荐
用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。
中介者模式(Mediator Pattern)是一种行为型设计模式,用于减少对象之间的直接相互依赖,使得对象间的交互通过一个中介者对象来进行协调。在中介者模式中,对象之间不再直接相互调用,而是通过中介者对象来传递消息...
咱们先来看下中介者模式(Mediator Pattern)的定义,它就是,用一个中介对象来封装一系列的对象交互,中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互,这种模式又称为调停...
MediatorPattern_Jonathan_Sey
主要介绍了Java设计模式之中介者模式(Mediator Pattern),需要的朋友可以参考下
提供者模式(Provider Pattern) 外观模式(Facade Pattern) 享元模式(Flyweight Pattern) 原型模式(Prototype Pattern) 责任链模式(Chain of Responsibility Pattern) 中介者模式(Mediator Pattern) 装饰模式...
中介者模式(Mediator Pattern) 19. 职责链模式(Chain of Responsibility Pattern) 20. 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23. 状态模式(State Pattern)
中介者模式(Mediator Pattern) 19. 职责链模式(Chain of Responsibility Pattern) 20. 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23. 状态模式...
18. 中介者模式(Mediator Pattern) 19. 职责链模式(Chain of Responsibility Pattern) 20. 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23. 状态模式...
中介者模式(Mediator Pattern) 19. 职责链模式(Chain of Responsibility Pattern) 20. 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23. 状态模式...
中介者模式(Mediator Pattern) 备忘录模式(Memento Pattern) 观察者模式(Observer Pattern) 状态模式(State Pattern) 空对象模式(Null Object Pattern) 策略模式(Strategy Pattern) 模板模式...
中介者模式(Mediator Pattern) 备忘录模式(Memento Pattern) 观察者模式(Observer Pattern) 状态模式(State Pattern) 策略模式(Strategy Pattern) 模板方法模式(Template Method ...
设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段...
中介者模式(Mediator Pattern) 19. 职责链模式(Chain of Responsibility Pattern) 20. 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23...
中介者模式(Mediator Pattern) 备忘录模式(Memento Pattern) 观察者模式(Observer Pattern) 状态模式(State Pattern) 空对象模式(Null Object Pattern) 策略模式(Strategy Pattern) 模板模式(Template ...
│ └─MediatorPattern │ ├─bin │ │ └─Debug │ ├─obj │ │ └─Debug │ │ └─TempPE │ └─Properties ├─20.OberverPattern │ ├─CatOberverPattern │ │ ├─bin │ │ │ └─Debug │ │ ├...
AbstractFactoryPattern AdapterPattern ...MediatorPattern MementoPattern ObserverPattern PrototypePattern ProxyPattern SingletonPattern StatePattern StrategyPattern TemplatePattern VisitorPattern
遍历聚合对象中的元素——迭代器模式(四) 遍历聚合对象中的元素——迭代器模式(五) 遍历聚合对象中的元素——迭代器模式(六) 中介者模式-Mediator Pattern 协调多个对象之间的交互——中介者模式(一) 协调多...
The Mediator Pattern Chapter 22. The Observer Pattern Chapter 23. The Memento Pattern Chapter 24. The Strategy Pattern Chapter 25. The Visitor Pattern Chapter 26. The Template Method Pattern Part 5 ...