youle88:网络相册开发(8)——Cairngorm架构浅析

Cairngorm是Adobe公司保举的Flex架构。关于它的文档少的可怜,我只发清楚明了这两个:Cairngorm中文文档:htyoule88tp://download.csdn.net/download/tcx1986/513560Develo


当前位置: 主页 >youle88


Cairngorm是Adobe公司保举的Flex架构。

关于它的文档少的可怜,我只发清楚明了这两个:

Cairngorm中文文档:

htyoule88tp://download.csdn.net/download/tcx1986/513560

Developing Flex RIAs with Cairngorm microarchitecture

http://www.adobe.com/devnet/flex/articles/cairngorm_pt1.html

Cairngorm 架构包括六部分:Model Locator(共享数据),View(视图),Front Controller(前端节制器),Command (敕令),Delegate(委托),Service(办事)。还有两个根基模块VO(数据工具),Event(事故)

Cairngorm流程大年夜致如下:界面由View组成,View绑定Model Locater中的数据。客户在View中操作孕育发生Event,Event被Front Controller所监听。Front Controller把Event绑定到Command,Command处置惩罚营业,创建Delegate,Delegate调用Service,Service远程造访Java。Java返回数据被Command获得并处置惩罚,更新Model Locater,Vyoule88iew由于和Model Locater数据绑定,也会自动更新。详情见Cairngorm中文文档

这是我Flex代码的布局

VO

一样平常与办事器中domain里的工具逐一映射。

必要留意的是转换时,数据类型的对应关系。

可参考转换表(http://download.csdn.net/download/ericder/677636)

BaseVO.as

Java代码

1.packagenet.sw.album.vo

2.{

3.import com.adobe.cairngorm.vo.IValueObject;

4.

5.public class BaseVO implements IValueObject

6.{

7.[Bindable]

8.public var id:Number;

9.[Bindable]

10.public var name:String;

11.[Bindable]

12.public var description:String;

13.[Bindable]

14.public var createtime:Date;

15.

16.

17.}

18.}

AlbumVO.as

Java代码

1.package net.sw.album.vo

2.{

3.[RemoteClass(alias="net.sw.album.domain.Album")]

4.public class AlbumVO extends BaseVO

5.{

6.[Bindable]

7.public var owner_id:Number;

8.[Bindable]

9.public var authority:int;

10.}

11.}

Model Locater

储存所有界面共享的数据,有点象session,不合的是保存在客户端

model locater采纳的是单例模式

AlbumModelLocater.as

Java代码

1.package net.sw.album.model

2.{

3.import mx.collections.ArrayCollection;

4.[Bindable]

5.public class AlbumModelLocater

6.{

7.

8.private static var albumModelLocater:AlbumModelLocater;

9.

10.public static const MYALBUMSTATE:String=youle88"myAlbumState";

11.

12.public var ownerId:Number=1;

13.public var albumId:Number;

14.public var myAlbums:ArrayCollection;

15.public var myFriends:ArrayCollection;

16.public var picturesAC:ArrayCollection;

17....... .....

18.

19.public static function getInstance():AlbumModelLocater {

20.if(albumModelLocater == null) {

21.albumModelLocater = new AlbumModelLocater();

22.}

23.return albumModelLocater;

24.}

25.

26.}

27.}

Front Controller

认真接管Event,并把Event和Command联系起来

AlbumController.as

Java代码

1.package net.sw.album.controller

2.{

3.import com.adobe.cairngorm.control.FrontController;

4.import net.sw.album.command.*;

5.import net.sw.album.event.menuItemClickEvent.*;

6.import net.sw.albyoule88um.event.*;

7.

8.import net.sw.album.model.AlbumModelLocater;

9.

10.

11.public class AlbumController extends FrontController

12.{

13.public function AlbumController()

14.{

15.initialiseCommands();

16.}

17.

18.public function initialiseCommands() : void

19.{

20.addCommand(DisplayMyAlbumEvent.EVENT_DISPLAY_MYALBUM,DisplayMyAlbumCommand);

21.addCommand(AddAlbumEvent.EVENT_ADD_ALBUM,AddAlbumCommand);

22.addCommand(ShowPhotoTileEvent.EVENTyoule88_SHOW_PHOTOTILE,ShowPhotoTileCommand);

23..............

24.}

25.

26.}

27.}

Delegate

都是布局化的器械,复制粘贴改几行代码就成了

AlbumDelegate.as

Java代码

1.package net.sw.album.business

2.{

3.

4.import com.adobe.cairngorm.business.ServiceLocator;

5.

6.import mx.rpc.IResponder;

7.import mx.rpc.remoting.RemoteObject;

8.

9.import net.sw.album.vo.AlbumVO;

10.

11.public class AlbumDelegate

12.{

13.private var responder : IResponder;

14.private var service : RemoteObject;

15.

16.public function AlbumDelegate(responder : IResponder )

17.{

18.this.service = ServiceLocator.getInstance().getRemoteObject( "albumService" );

19.this.responder = responder;

20.}

21.

22.public function findAlbumsByUserID() : void

23.{

24.var call : Object = service.getAll();

25.call.addResponder( responder );

26.}

27.

28.public function addAlbum(album:AlbumVO):void

29.{

30.var call : Object = service.saveAlbum(album);

31.call.addResponder( responder );

32.}

33.

34.

35.}

36.}

Service

定义远程历程调用,这里应用的是RemoteObject

Services.mxml

Xml代码

1.

2.

5.

8.

9.

11.

12.

13.

15.

16.

17.

18.

发表评论
加载中...

相关文章