Sealyu

          --- 博客已遷移至: http://www.sealyu.com/blog

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks
          什么是Cairngorm?
           
          Cairngorm(中文名:“煙水晶”?)是一個輕量級的Flex RIA程序開發框架,從而使程序可擴展性、可維護性都大大提高,其本身并不是一個完整的企業應用,它只是提供了一個開發骨架,Adobe稱之為體系。

           
          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)
           
          轉自:http://www.soave.com.cn/post/2008/06/what-is-cairngorm.aspx



          學習Cairngorm站點、文章收集.

          1:http://www.davidtucker.net/category/cairngorm/   入門強烈推薦

          *http://www.cairngormdocs.org/tools/CairngormDiagramExplorer.swf     cairngorm圖解法表示

            http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm 推薦

          2:http://opensource.adobe.com/wiki/display/cairngorm/Developer+Documentation

          3:http://www.adobe.com/devnet/flex/articles/graduating_pt1.html

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

          5:http://jessewarden.com/2007/08/10-tips-for-working-with-cairngorm.html

          6:Cairngorm學習——使用WebService和HTTPService服務

          7:AIR也可以Cairngorm   --     http://www.ericfeminella.com/blog/2007/07/16/air-cairngorm-air-extensions-for-cairngorm/


          實例:http://www.duzengqiang.com/blog/article.asp?id=198     Flex Example: HTTPService & Cairngorm 2.2


          posted on 2009-07-06 22:01 seal 閱讀(445) 評論(0)  編輯  收藏 所屬分類: Flex+ActionScript
          主站蜘蛛池模板: 浦江县| 大渡口区| 图木舒克市| 两当县| 玛纳斯县| 渭南市| 葫芦岛市| 比如县| 如皋市| 阳新县| 巴中市| 都匀市| 潮安县| 韶山市| 新野县| 翁牛特旗| 沽源县| 梅河口市| 宁城县| 九龙城区| 桂林市| 威信县| 公安县| 张家川| 德江县| 灵石县| 蓬莱市| 德格县| 伊金霍洛旗| 千阳县| 定兴县| 崇阳县| 宝鸡市| 金平| 崇文区| 延吉市| 通渭县| 司法| 河间市| 安平县| 故城县|