MVP: The application of interface and business logic separation in WinForm
Mvp,model-view-presenter's abbreviation.
On MSDN, download an example, http://www.microsoft.com/china/msdn/library/architecture/architecture/architecturetopic/MVP.mspx?mfr=true
The implementation structure adopted
On the blog http://www.agilelabs.cn/blogs/wind_tower/archive/2006/01/26/626.aspx, see the implementation of the structure
In the C # development environment, in order to improve the development efficiency of the interface, data binding can be used in the form. In this way, it is more convenient to provide a data source in view, using the structure defined on MSDN.
At the same time, in order to improve the response to customer requests, the use of multithreading. Because the data binding in view and the business logic of multi-threading in presenter need to access the data source in view at the same time, for some specific multithreading needs, we also need presenter to provide the public function to refresh the view. is not fully implemented: After the presenter business logic is updated, view can automatically refresh
=====================================================
WinForm MVP Implementation
Previously written WinForm projects are the interface and implementation of the logic are put together, since the learning of MVC3, and after looking at the WPF MVVP, think WinForm program can write this way.
First define the View interface:
Public where T:class { setvoid bindingdata (T model);}
Then define the presenter interface:
<summary> ///</summary> class void void void DeleteData (T model); }
Classes that implement the Ipresention<t> interface:
PublicClass datadictpresentation:ipresention<resourcedict>{iview<resourcedict>_view; Iview<ilist<resourcedict>>_viewlist;Public Datadictpresentation (iview<resourcedict>View) {_view =Viewif (_view. Model! =Null) {_view. BindingData (_view. Model); } }Public Datadictpresentation (iview<ilist<resourcedict>>View) {_viewlist =View PageIndex =1; PageSize =14; }Publicint PageIndex {GetSet; }Publicint PageCount {get; setpublic int PageSize {setpublic void InsertData (Resourcedict model) {} public void UpdateData (Resourcedict model) {} public void Query (resourcedict filter) {} public void DeleteData (resourcedict model) {}}
Finally implemented on the form page:
PublicPartialClass Datadictbox:form, iview<resourcedict>{PrivateDatadictpresentation presentation;PublicDatadictbox () {InitializeComponent (); Initialize (); }PrivateStaticDatadictbox _instance;PublicStaticDatadictbox Instance {Get{if (_instance = =null | |_instance. isdisposed) {_instance =NewDatadictbox (); }Return _instance;} } private voidthis. Load + = delegate {presentation = new datadictpresentation (thispublic resourcedict Model {get; setpublic voidpublic void SetData (resourcedict item) {}
This completes a preliminary model of the MVP structure.
The implementation of MVP design pattern