cairngorm commands deal with lots of things

Yeah.

As the best practice says: the command and event should be One-To-One in cairngorm . If doing so, we would have lots of command and event files.

So here is my way in solving the problem, see codes below.

[b]PhotoEvent.as[/b] has two event types.

import com.adobe.cairngorm.control.CairngormEvent;
import com.babytree.photoUpload.control.MainController;


public class PhotoEvent extends CairngormEvent
{
public function PhotoEvent (type:String)
{
super(type);
}
//get all albums of a user
public static const GET_ALBUMSLIST:String = "get_albumslist";
//get all photos of an album
public static const GET_ALBUMPHOTOS:String = "get_albumphotos";
}


[b]PhotoCommand.as[/b] deal with PhotoEvent; PhotoServiceDelegate.as contains HTTPService Call.

public class PhotoCommand implements ICommand,IResponder
{
private var model : ModelLocator = ModelLocator.getInstance();
private var photoServiceDelegate:PhotoServiceDelegate;
private var photoEvent:PhotoEvent;
// functions ============================

public function execute( event:CairngormEvent ) : void
{
photoEvent = event as PhotoEvent;
photoServiceDelegate = new PhotoServiceDelegat(this as IResponder);
switch(photoEvent.type){
case PhotoEvent.GET_ALBUMSLIST:
photoServiceDelegate.getUserAlbums(model.userVO);
break;
case PhotoEvent.GET_ALBUMPHOTOS:
photoServiceDelegate.getAlbumPhotos(model.userVO);
break;
}
}

public function result( data:Object ) : void
{
switch(photoEvent.type){
case PhotoEvent.GET_ALBUMSLIST:
//do something
break;
case PhotoEvent.GET_ALBUMPHOTOS:
//do something
break;
}
}

public function fault( info : Object ) : void
{
trace("fault in PhotoCommand.as ==== Event.type is ===" + photoEvent.type);
}

}



My Question is : the way I hold [color=red]PhotoEvent[/color] and reuse it in result function is right ?

is there any advice ?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值