PureMVC框架的目标很明确,就是把程序分为低耦合的三层:Model、View和Controller。

通过使用PureMVC后,我们的代码将集中分为以下几个部分:Façade、Command、Mediator、Proxy以及UI部分,还有一些数据结构的定义如Value Object,所有核心的逻辑都在Command、Mediator和Proxy中。

1.      Façade:

管理着Controller、Model和View,并且通过他们建立起Notification和Command以及Notification和Mediator之间的消息映射。

其中Controller、Model和View都是在框架中实现,对用户来讲是不可见的。

一般一个Application都有一个Façade子类,并在系统初始化的时候进行Façade的初始化。

有3个比较重要的Protected初始化函数:

initializeController() – 初始化Notification和Command之间的映射

如registerCommand(LOGIN, LoginCommand);

initializeModel() – 初始化Model层,主要是Proxy的注册

如registerProxy(new SearchProxy());

initializeView() – 初始化View层,主要是Mediator,并Mediator指定具体的Notification Body,通常就是具体的UI view

如registerMediator(new ApplicationMediator());

通常Proxy和Mediator都是在收到具体Notification后第一次调用的时候进行注册,特别是Mediator,它需要一个对UI view的具体引用,在façade中无法得到

2.      Command

一般处理系统主要的Business Logic。通过Façade中的Controller注册并侦听每个Notification,当收到某个Notifiaction后,Controller会实例化一个Notification对应的Command类对象,然后调用Command的execute()方法并将Notification作为参数传递给它。

Command包括两种SimpleCommand和MacroCommand,实际上MacroCommand就比SimpleCommand多维护一个subCommands数组,在调用MacroCommand的execute方法是,会遍历该数组并按顺序调用每个command的execute方法

在Command里可能会处理以下逻辑:

A.     注册或删除Mediator、Proxy以及其他Command

B.     发送Notification通知其他Command或者Mediator做出响应

C.     获取Proxy和Mediator对象,直接操作它们

3.      Mediator

Mediator是界面UI部分和系统其他部分交互的中介。它的主要职责是处理UI和其他Mediator或者Command发出的Notification。

Mediator通过2种方式监听着系统发出的消息

  1. 普通的addEventListener(eventName, onHandler)
  2. 定义感兴趣的Notification和收到Notification后的处理函数

如下代码:

override public function listNotificationInterests():Array{

return [

ApplicationFacade.MY_CLICK

];

}

override public function handleNotification(notification:INotification):void{

switch(notification.getName())

{

case ApplicationFacade.MY_CLICK:

myView.text.text = notification.getBody() as String;

break;

}

}

最新文章

  1. salesforce 零基础学习(四十三)运算取余
  2. javascript马赛克遮罩图片切换效果:XMosaic.js(转)
  3. Linux服务器的那些性能参数指标
  4. HDU5781 ATM Mechine(DP 期望)
  5. Database.com SOQL and SOSL Reference
  6. 想当站长请立即使用Orchard
  7. Mathematical operation
  8. 精通CSS :nth-child伪类
  9. Feister network
  10. FOR XML PATH 解决联接返回结果集各记录问题
  11. Android:实现退出确认对话框
  12. SQL Server 内存管理
  13. cocos2d-x -- 渠道SDK【棱镜】接入(2)
  14. 让ecshop显示商品销量或者月销量
  15. Python使用ctypes访问C代码
  16. 什么是IPFS?(三)
  17. Java基础---Java---基础加强---类加载器、委托机制、AOP、 动态代理技术、让动态生成的类成为目标类的代理、实现Spring可配置的AOP框架
  18. Git的一些操作
  19. [Spark]如何设置使得spark程序不输出 INFO级别的内容
  20. [Leetcode]27. 移除元素

热门文章

  1. 《学习的艺术》 (The Art of Learning)——划小圈 (Making Smaller Circles)
  2. 分布式版本控制系统Git-----5.Git 的push命令总结
  3. vs2008试用版的评估期已经结束解决办法
  4. Android的JunitTest
  5. 第九十九节,JavaScript数据类型
  6. js--事件对象的理解5-
  7. javascript 奇淫巧技1
  8. sublime eslint setup
  9. Linux help websites
  10. linux下IPC通信