Cairngorm学习——什么是Cairngorm?

by 蛐蛐 5. June 2008 15:09
参考文档:
Cairngorm Microarchitecture for Adobe Flex
cairngormdocs
 
什么是Cairngorm?
 
Cairngorm(中文名:“烟水晶”?)是一个轻量级的Flex RIA程序开发框架,从而使程序可扩展性、可维护性都大大提高,其本身并不是一个完整的企业应用,它只是提供了一个开发骨架,Adobe称之为体系。
 
Cairngorm流程图
 
 
 
Cairngorm体系
 
主要包括以下几个部分:
 
1、VO(Value Object)
 
IValueObject 和 ValueObject 只是为了提高VO类的可读性,表示该类是一个ValueObject类,其它没有任何实际作用。其可能是为将来而设计的,我们在应用过程中不需要实现任何接口函数。
 
2、Model
 
定义了ModelLocator接口,我们只需要实现该接口,把所需要绑定的数据保存在这里。通常我们都采用单例模式(Singleton Pattern)来实现,并按照项目模块进行分类,避免把整个项目的所有数据都保存在一个类文件中。换句话说,ModelLocator是整个系统的数据中心。
 
 3、View
 
 有ViewHelper.as 和 ViewLocator.as,在Cairngorm2.2.1版本中已被废除。
 
 4、Commands
 
定义了ICommand接口,该接口定义了一个唯一需要实现的方法execute(),这其实就是典型的命令模式,我们只要实现此接口,并不需要关心其具体实现方式。
 
 5、Control
 
 含三个基类:CairngormEvent、CairngormEventDispatcher和FrontController。

(1)CairngormEvent:

继承flash.events.Event,其包含一个data成员,用来传递参数数据之用。

(2)CairngormEventDispatcher:

采用单例模式(Singleton Pattern),用来广播用户发起的自定义动作事件。

(3)FrontController:

相当于控制中心,在这里你要做的工作是将事件(CairngormEvent)和命令(Command)之间的映射关系注册在它的
成员commands(Dictionary类型)中,通过下面的类似方法进行注册:
addCommand( GetProductsEvent.EVENT_GET_PRODUCTS, GetProductsCommand );

以后,凡是CairngormEventDispatcher广播出来的事件,首先都会在这里查找,找到对应的event对应的command后,
便执行Command的execute()方法。


FrontController必须要在你的系统中实例化,具体的实例化方法如下:

1<mx:Application xmlns:control="com.domain.projectname.control.ShopController">
2 ...
3 <control:ShopController id="controller" />
4 ...
5</mx:Application>
 
 6、Business
 
 IServiceLocator接口:

提供了HTTPService、WebSercice、RemoteObject三种RPC服务。使用时候,将需要的RPC服务登记在该接口中,
以mxml形式采用单例模式(Singleton Pattern)实现IServiceLocator,如下面使用例子:

 
1<cairngorm:ServiceLocator
2 xmlns:mx="http://www.adobe.com/2006/mxml"
3 xmlns:cairngorm="http://www.adobe.com/2006/cairngorm">
4
5 <mx:RemoteObject id="productService" destination="productServiceImpl" showBusyCursor="true">
6 </mx:RemoteObject>
7
8 <mx:RemoteObject id="creditCardService" destination="creditCardServiceImpl" showBusyCursor="true">
9 </mx:RemoteObject>
10
11 <mx:HTTPService id="XXXService" url="URL" showBusyCursor="true" useProxy="false" resultFormat="e4x">
12 </mx:HTTPService>
13
14</cairngorm:ServiceLocator>
 
 需要在系统中实例化,具体的实例化方法如下:
 
1<mx:Application xmlns:business="com.adobe.cairngorm.samples.store.business.*">
2 ...
3 <business:Services id="services" />
4 ...
5</mx:Application>
 
在某个Delegate类中的使用方法:
 
1this.service = ServiceLocator.getInstance().getRemoteObject( "productService" );
 
之后,就可以进行相关的函数调用了。
 
后记:
 
发现《基于Cairngorm的Flex应用程序设计》中文版电子书,顺便提供下载:基于Cairngorm的Flex应用程序设计.pdf (1.00 mb)

Currently rated 3.2 by 17 people

  • Currently 3.235294/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Flex/AIR

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

RecentComments

Comment RSS