PureMVC 框架总结收录
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种方式监听着系统发出的消息
- 普通的addEventListener(eventName, onHandler)
- 定义感兴趣的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;
}
}
最新文章
- salesforce 零基础学习(四十三)运算取余
- javascript马赛克遮罩图片切换效果:XMosaic.js(转)
- Linux服务器的那些性能参数指标
- HDU5781 ATM Mechine(DP 期望)
- Database.com SOQL and SOSL Reference
- 想当站长请立即使用Orchard
- Mathematical operation
- 精通CSS :nth-child伪类
- Feister network
- FOR XML PATH 解决联接返回结果集各记录问题
- Android:实现退出确认对话框
- SQL Server 内存管理
- cocos2d-x -- 渠道SDK【棱镜】接入(2)
- 让ecshop显示商品销量或者月销量
- Python使用ctypes访问C代码
- 什么是IPFS?(三)
- Java基础---Java---基础加强---类加载器、委托机制、AOP、 动态代理技术、让动态生成的类成为目标类的代理、实现Spring可配置的AOP框架
- Git的一些操作
- [Spark]如何设置使得spark程序不输出 INFO级别的内容
- [Leetcode]27. 移除元素