花了大半天的時間,讀完了Steven Webster關於cairngorm微架構的幾篇介紹,總結一下,印象最深的主要有三塊,
1、全域唯一的ModelLocator加上DataBinding,簡化了client model(或者說state)的管理及view的更新,可以避免寫入程式碼更新view的痛和極大的不方便及維護代價,這需要合理設計各view compomnent使之支援完全綁定化;
2、FrontController加上事件機制(一個全域的事件管理對象),解耦了user gesture對具體動作(或者說command)的直接調用,這樣也有利於清晰的劃分用例,由user gesture派發的event說要想做什麼(不需要知道怎麼做),frontcontroller會分配具體的command去做事;
3、ServiceLocator加Command(或者應該說Command加ServiceLocator)解除了command實現與底層服務之間的耦合,這樣command只需借用serviceLocator(間接借用,中間還有一層BusinessDelegate)去實現所需功能,具體通過那個服務(HttpService、WebService、RemoteObject)實現的由servicelocator處理,command會在與server互動後(成功和失敗的處理)更新client state也即ModelLocator,這樣會自然觸發view的更新(1)
即使不用cairngorm微架構,其中許多好的實踐還是可使用的,例如上面三點。
Cairngorm開發流程及調試驗
Adding a New Feature to a Cairngorm Application
When you add a new feature to a Cairngorm application, it is as simple as the following process:
1. Register an event and command with the Front Controller using addCommand().
2.
Implement a new command as follows:
1. Implement the execute() method to do the work.
2.
Implement the onResult() method to handle any results from the server:
1. Any results are used to update the Model Locator.
2. The Model Locator automatically updates the view.
3. Add any new service calls that the Command requires for the Business Delegate.
4. If these service calls require new services, add them to the Service Locator.
Debugging a Cairngorm Application
Furthermore, debugging a Cairngorm application follows the same predictable steps. If a desired feature doesn't perform in response to a user gesture, the debug cycle is always the same:
1. Check whether the event is registered with the Front Controller.
2. Check whether the execute() method is called on the command by the Controller.
3. Check that the appropriate delegate methods are called.
4. Check that the onResult() method is called in the command.
5. Check that the model is updated in the Model Locator.
With these five steps, it's painless to isolate a problem in an application and fix it當前PERTChart控制項開發情況
pertchart現階段的問題及重構準備
許多問題的出現都是相關聯的
1、各view component的未實現完全的綁定化(會造成額外開發負責度)
2、對user gesture的處理直接調用具體動作、分散在各處代碼中
3、擁有全域唯一的client DataModel,但負責了過多的任務
4、對service的調用處理也是直接具體到了細節
5、使用了Application.application作為全域事件管理對象
可以說pertchart的應用不大,但實現功能(還有for future的)及互動卻很齊全,有些
東西可能會具體重構工作分析如下:
1、可能會有較大的工作量,各處的view的代碼會有一大部分集中到相關component中
2、對user gesture的處理借用cairngorm方式
3、把datamodel現處理的分給各command(各具體動作)
4、5都借用cairngorm方式,較容易
6、pertchart還有個問題便是與server互動的強制同步問題
重構可能使pertchart的開發採用較多cairngorm的實踐或者直接採用cairngorm架構
~各種開發工具或者說平台雖說可以學習並應用,但其總有各自的特點處,加以瞭解再做進一步會好許多,在Flex應用開發上,通過Cairngorm可以瞭解其提倡的實踐模式(其特點了),這樣就可以把為其冠以其他平台的開發習慣的開發方式摒棄,採用更合適的了!