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.

PhotoEvent.as 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";
	}


PhotoCommand.as 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 PhotoEvent and reuse it in result function is right ?

is there any advice ?

你可能感兴趣的:(Adobe)