MVC Pattern
OVERVIEW
從比較宏觀的角度介紹Venus ;用設計模式來描述就是MVC+Factory Pattern。
Model-View-Controller
MVC模式是一種非常常用的設計模式,其原理不再贅述。在Venus 中也采用了此模式——模型數據-顯示-編輯器,分別用類CAnyDocument,CAnyView,CAnyEdior來實現。其中:
l CAnyDocument
文檔管理
l CAnyView
模型顯示,場景管理
l CAnyEditor
模型編輯器接口,即創建模型的操作,如創建Sphere,Box,Line等。
Extrend
為了便于Editor的管理和功能的擴充,增加了兩個管理類CEditorMgr和CEditorFactory。
l CEditorFactory
采用參數化的工廠方法管理所有的Editor。通過editor的ID用相應的Editor Creator就可以創建出Editor實例。
l CEditorMgr
一個CAnyView一次只能有一個活動的Editor,各種操作的關系有的存在堆棧式的關系,因而用CEditorMgr管理當前View中的Editor。
l CEditorCreator
提供創建Editor的接口。通常,每實現一個CAnyEditor的子類,就需要一個Creator與之對應,以便注冊到CEditorFactory工廠中。
Classes structure
各類之間的關系如下:

MVC Pattern
注:XXX代表子類,如CSphereEditor,CBoxEditor等
Demo
完整程序
完整程序20070520Full
更新補丁20070522
Contract
mythma@126.com