Duran's technical life
          踏踏實實學技術,認認真真做研究。

          iteration::two Cairngorm 0.99 開發指南
          @author sakis
          @version 0.1

          #0
          MXML優點:使用方便,XML代碼簡潔易懂
          缺點:事件、函數、界面描混在一起。程序規模大了難于開發維護。

          #1
          Cairngorm框架是iterationtwo推出的號稱基于JEE Best Practice的Flex程序開發的light-weight framework。(恩,light-weight這個詞還真是流行呢)。目前最新版本為0.99。

          Cairngorm的結構如下:
          org
          └─nevis
              └─cairngorm
                  ├─application
                  │      CairngormApplication.as
                  │
                  ├─business
                  │      Responder.as
                  │      ServiceLocator.as
                  │
                  ├─commands
                  │      Command.as
                  │      SequenceCommand.as
                  │
                  ├─control
                  │      Event.as
                  │      EventBroadcaster.as
                  │      FrontController.as
                  │
                  ├─model
                  │      ModelLocator.as
                  │
                  ├─view
                  │      ViewHelper.as
                  │      ViewLocator.as
                  │
                  └─vo
                          ValueObject.as


          #2
          下面給大家簡單介紹Cairngorm的實現思路。

          #2.1
          Command/FrontController將Event與Viwe分離。
          FrontController實現Singleton模式(以下簡寫為SP)。所有自定義的Command在要在FrontController構造函數中實例化并以關聯數組的方式注冊FrontController#addCommand(eventType:String, commandInstance:Command)。EventBroadcaster實現SP。Event類的結構為{type:eventType, data:eventData}。我們通過EventBroadcaster#broadcastEvent(eventType:String, eventData:Object)發布Event。Event發布后,與eventType對應的command instance執行Command#execute(event:Event)。

          BTW:在Cairngorm的源碼中,eventType、commandName、eventName混用,我統一用eventType。

          #2.2
          ServiceLocator將Remote Service聲明與View分離。
          ServiceLocator實現SP。在Cairngorm的demo中,又通過Delegate對象解除Command/Responder和ServiceLocator之間的依賴。這個Delegate做的事情其實意義不大,就是調用ServiceLocator中的Method,設置莫個Responder為相應遠程方法的handler。個人覺得無謂地增加了代碼量,而且Delegate對象也沒實現SP,也就是說我們每次調用一次Remote Service中的Method,都要new一個Delegate對象,實在浪費。

          #2.3
          ViewLocator/ViewHelper將View(MXML)中夾雜的function與View分離。
          ViewHelper有點意思,當一個ViewHelper在某個MXML頁面中聲明時,如<view:LoginViewHelper id="loginViewHelper" />。ViewHelper能自動取得所在MXML對象的引用,并通過ViewLocator#register(id, this:ViewHelper)將自身注冊到ViewLocator中。ViewLocator實現SP。借助ViewLocator/ViewHelper,我們就可以方便的調用不同MXML頁面中的方法。

          #2.4
          ModelLocator是一個marker interface,程序中Model可以放在某個ModelLocator方便調用。

          #2.5
          ValueObject也是一個marker interface, 基本不需要。

          #3
          Cairngorm.99給我們開發Flex程序提供了很不錯的架構模式,M/V/C/Remote之間可以做到完全解構。但在實際開發時沒有必要死扣,代碼結構清晰有活力就好。

          posted on 2005-09-07 21:49 Duran's technical life 閱讀(887) 評論(0)  編輯  收藏 所屬分類: 技術積累
           
          主站蜘蛛池模板: 顺昌县| 黄大仙区| 本溪| 沛县| 大埔区| 南郑县| 千阳县| 青州市| 唐山市| 苍溪县| 改则县| 隆回县| 和静县| 南宁市| 石屏县| 海林市| 宜昌市| 黑水县| 锡林郭勒盟| 万载县| 秭归县| 长岭县| 静宁县| 静安区| 乐东| 都匀市| 南岸区| 洛宁县| 涟水县| 永宁县| 景德镇市| 山丹县| 荆州市| 鸡泽县| 江山市| 新和县| 青海省| 维西| 横峰县| 蓬莱市| 柳州市|