The implementation of MVP design pattern

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.