2012-09-17 35 views
2

我想使用「演示者優先」方法(演示者通過構造函數調用使用依賴注入將其自身附加到構造函數中的視圖和模型中)。是否可以使用MVP方法實例化Main中的演示者?

我的表單是一個包含兩個用戶控件的MainForm,每個用戶控件都有自己的演示者,但共享模型,所以我在Main中創建所有演示者,通過讓相關用戶控件傳遞給演示者,這些來自FormMain的控件,並將模型的單個實例傳遞給所有演示者。

static void Main() 
{ 
Application.EnableVisualStyles(); 
Application.SetCompatibleTextRenderingDefault(false); 

IDocumotiveCaptureView view = new DocumotiveCaptureView(); //this is the MainForm 
IDocumentModel model = new DocumentModel(); //single model 
IDocumotiveCapturePresenter Presenter = new DocumotiveCapturePresenter(view, model); //MainForm's presenter 
IControlsPresenter ControlsPresenter = new ControlsPresenter(view.ControlsView, model); //ControlsPresenter - attached to the user control via view.ControlsView 
IDocumentPresenter DocumentPresenter = new DocumentPresenter(view.DocumentView, model);//DocumentPresenter - attached to the user control via view.DocumentView) 

Application.Run((Form)view);               
} 

任何人都可以在這種方法中看到任何固有的不良或錯誤?我意識到這可能是主觀的,但我對MVP很陌生,希望得到一些反饋。

回答

3

如果它適合你,那當然沒關係。 MVP不是一種宗教。它甚至不再被認爲是單一模式。兩種最流行的解釋現在似乎是被動觀察和監督控制器。

你的情況主要方法是組成根(搜索由馬克·西曼任何答案),它是給你做一個很好的地方。但它不是唯一的地方。請參閱Model-View-Presenter in WinForms

相關問題