`

Mediator 中介 行为模式

阅读更多

    Mediator 中介 行为模式,用一个中介来封装一些列的对象操作。中介使得对象之间不需要显示的相互引用,从而使其耦合松散,而且可以独立的改变他们之间的交互。

 

    面向对象鼓励将行为分布到各个对象中。这种分布可能会导致对象见有许多连接。在最坏的情况下,每一个对象都知道其他的对象。在PureMVC中就是使用Mediator,来中介对象之间的操作,对象只要和Mediator通信就可以了。

 

   

 

我们就直接拿 PureMVC 框架的源代码作为例子:

 

IMediator.as

package org.puremvc.interfaces {
	public interface IMediator {
		function getViewComponent():Object;
		function listNotificationInterests( ):Array;
		function handleNotification( notification:INotification ):void;
	}
}
 

 

Mediator.as

package org.puremvc.patterns.mediator {
	import org.puremvc.interfaces.*;
	import org.puremvc.patterns.observer.*;
	import org.puremvc.patterns.facade.Facade;
	
	public class Mediator extends Notifier implements IMediator, INotifier {
		public static const NAME:String = 'Mediator';

		public function Mediator( viewComponent:Object=null ) {
			this.viewComponent = viewComponent;	
		}
	
		public function getMediatorName():String  {	
			return Mediator.NAME;
		}
	
		public function getViewComponent():Object {	
			return viewComponent;
		}
        
		public function listNotificationInterests():Array  {
			return [ ];
		}
 
		public function handleNotification( notification:INotification ):void {}
		
		protected var viewComponent:Object;
	}
}
 

   这个具体Mediator有一个对viewComponent的引用,viewComponent通过发出时间来告诉Mediator,这个对象要干什么,然后Mediator把这个对象要做的事情转发出去,供Command 和 其他对象的Mediator去接受处理。

 

 

 

  • 大小: 33.3 KB
分享到:
评论

相关推荐

    (行为型模式) Mediator 中介者模式

    C#面向对象设计模式 (行为型模式) Mediator 中介者模式 视频讲座下载

    C#面向对象设计模式纵横谈(17):(行为型模式) Mediator 中介者模式

    C#面向对象设计模式纵横谈(17):(行为型模式) Mediator 中介者模式

    C#面向对象设计模式纵横谈(17):(行为型模式) Mediator 中介者模式 (Level 300)

    C#面向对象设计模式纵横谈(17):(行为型模式) Mediator 中介者模式 (Level 300)

    中介者模式(Mediator Pattern)原理图

    中介者模式(Mediator Pattern)是一种行为型设计模式,用于减少对象之间的直接相互依赖,使得对象间的交互通过一个中介者对象来进行协调。在中介者模式中,对象之间不再直接相互调用,而是通过中介者对象来传递消息...

    JAVA设计模式之行为模式

    这是JAVA设计模式中属于行为模式的部分,包括Template(模板模式)、Chain of Responsibility(责任链模式)、Memento(纪念品模式)、Mediator(中介模式)、Strategy(策略模式)、State 、Observer(观察者模式)、Visitor...

    c++设计模式-行为型模式-中介者模式

    c++设计模式-行为型模式-中介者模式;qt工程;c++简单源码; 中介者(Mediator)模式的定义:定义一个中介对象来封装一系列对象之间的交互,使原有对象之间的耦合松散,且可以独立地改变它们之间的交互。中介者模式...

    详解iOS应用的设计模式开发中Mediator中介者模式的使用

    何为中介者模式?  面向对象的设计鼓励把行为分散到不同对象中,这种分散可能导致对象之间的相互关联。在最糟糕的情况下,所有对象都彼此了解并相互操作。  虽然把行为分散到不同对象增强了可复用性,但是增加的...

    java中介者模式.docx

    Mediator模式也叫中介者模式,是由GoF提出的23...Mediator模式是行为模式之一,在Mediator模式中,类之间的交互行为被统一放在Mediator的对象中,对象通过Mediator对象同其他对象交互,Mediator对象起着控制器的作用。

    C#面向对象设计模式纵横谈(视频与源码)

    C#面向对象设计模式纵横谈(17):(行为型模式) Mediator 中介者模式 C#面向对象设计模式纵横谈(18):(行为型模式) Iterator 迭代器模式 C#面向对象设计模式纵横谈(19):(行为型模式) Observer 观察者模式 C#...

    23种java设计模式

    3、行为模式:Iterator(迭代模式)、Template(模板模式)、Chain of Responsibility(责任链模式)、Memento(纪念品模式)、 Mediator(中介模式)、Interpreter(解释器模式)、Strategy(策略模式)、State 、Observer...

    PHP设计模式之中介者模式(Mediator Pattern)入门与应用案例详解

    咱们先来看下中介者模式(Mediator Pattern)的定义,它就是,用一个中介对象来封装一系列的对象交互,中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互,这种模式又称为调停...

    JAVA设计模式chm文档

    行为模式: 设计模式之Template 设计模式之Memento(备忘机制) 设计模式之Observer 设计模式之Chain of Responsibility(职责链) 设计模式之Command 设计模式之State 设计模式之Strategy(策略) 设计模式之Mediator(中介...

    设计模式之11个行为型模式

    行为型简介职责链模式(ChainofResponsibility)命令模式(Command)解释器模式(Interpreter)迭代器模式(Iterator)中介者模式(Mediator)备忘录模式(Memento)观察者模式(Observer)状态模式(State)策略模式(Strategy)模板...

    设计模式文档 chm

    行为模式: 设计模式之Template 设计模式之Memento(备忘机制) 设计模式之Observer 设计模式之Chain of Responsibility(职责链) 设计模式之Command 设计模式之State 设计模式之Strategy(策略) 设计模式之Mediator(中介...

    23种设计模式 (创建型,结构型,行为型)

    中介者模式(Mediator Pattern) 19. 职责链模式(Chain of Responsibility Pattern) 20. 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23. 状态模式...

    C++设计模式(Design Pattern)范例源代码

    23种设计模式(Design Pattern)的C++实现范例,包括下面列...中介者模式(Mediator) 备忘录模式(Memento) 观察者模式(Observer) 状态模式(State) 策略模式(Strategy) 模板方法模式(Template Method) 访问者模式(Visitor)

    01-制造工具的工厂模式(1).html

    在书中,作者们将这二十三种设计模式分成了三类,分别是创建型模式、结构型模式和行为型模式。...中介者模式( Mediator ) 解释器模式( Interpreter ) 书中通过一幅图,剖析了这二十三种设计模式的关系。

    09-通过容器实现的外观模式(2).html

    在书中,作者们将这二十三种设计模式分成了三类,分别是创建型模式、结构型模式和行为型模式。...中介者模式( Mediator ) 解释器模式( Interpreter ) 书中通过一幅图,剖析了这二十三种设计模式的关系。

    00-初探 Laravel 和其中的设计模式(3).html

    在书中,作者们将这二十三种设计模式分成了三类,分别是创建型模式、结构型模式和行为型模式。...中介者模式( Mediator ) 解释器模式( Interpreter ) 书中通过一幅图,剖析了这二十三种设计模式的关系。

    12-附录 1 设计模式的七大原则(1).html

    在书中,作者们将这二十三种设计模式分成了三类,分别是创建型模式、结构型模式和行为型模式。...中介者模式( Mediator ) 解释器模式( Interpreter ) 书中通过一幅图,剖析了这二十三种设计模式的关系。

Global site tag (gtag.js) - Google Analytics