PureMVC学习(二)

Command与Mediator和Proxy交互,应避免Mediator与Proxy直接交互。看下面一个用于程序"启动"的Command:

package com.wf.controller
{
	import org.puremvc.as3.core.Model;
	import org.puremvc.as3.patterns.command.MacroCommand;

	/**
	 * 程序开始时执行的MacroCommand
	 */ 
	public class StartupCommand extends MacroCommand
	{
		/**
		 * 添加子Command初始化MacroCommand
		 */ 
		override protected function initializeMacroCommand():void
		{
			addSubCommand(ModelPrepCommmand);
			addSubCommand(ViewPrepCommand);
		}
	}
}

这是一个添加了两个子Command的MacroCommand.执行时,两个子命令会按照FIFO的顺序被执行。

一般,开启(startup)主要有两个过程:Model初始化与View初始化。

package com.wf.controller
{
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	//创建Proxy对象,并注册
	public class ModelPrepCommand extends SimpleCommand
	{
		//由MacroConmmand调用
		override public function execute(notification:INotification):void
		{
			facade.registerProxy(new SearchProxy());
			facade.registerProxy(new PrefsProxy());
			facade.registerProxy(new UserProxy());
		}
	}
}

Command并没有操作或初始化任何的Model数据.Proxy的职责才是取得、创建 和初始化数据对象。

package com.wf.controller
{
	import mx.core.Application;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	//创建Mediator,并把他们注册到View
	public class ViewPrepCommand extends SimpleCommand
	{
		override public function execute(notification:INotification):void
		{
			var app:PureMvcStudy = notification.getBody() as PureMvcStudy;
			facade.registerMediator(new ApplicationMediator(app));
		}
	}
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值