Previous things-Mvp2

Source: Internet
Author: User

After reading the reply, I found that some people have different understandings of MVP and I have written the following.

I mainly refer to the following articles

Http://codebetter.com/blogs/jeremy.miller/articles/129542.aspx

Http://codebetter.com/blogs/jeremy.miller/archive/2006/02/01/137457.aspx

Http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx

Http://www.martinfowler.com/eaaDev/SupervisingPresenter.html

Http://www.martinfowler.com/eaaDev/PassiveScreen.html

Why MVP is used in asp.net:

One of the most important principles in software design is "separation of concerns". Each piece of code has only one responsibility, so that the program can have good maintainability. Even at the starting point of encoding, it should be clear that only one problem can be solved at a time, for example, I want to focus only on the business logic, regardless of the database structure, html, and so on.

The traditional approach to building maintainable user interface code is the MVC mode. Unfortunately, asp.net optimized RAD and did not focus on creating maintainability code. The asp.net model itself did not provide good support for MVC, many asp.net programs mix data access, html tags, and business logic, and the code-behind model does not have a good separation of concerns. In addition, code-behind is difficult to perform unit tests, these are the reasons why MVPs should be introduced.

MVP and MVC problems:

What is the role of Code-behind?

Code-Behind cannot be the controller of MVC. It can only be used as a simple View. Many maintenance problems are caused by using Code-Behind as the controller. In MVP, Presenter cannot reference the System. Web namespace. P depends on V. Even in other modes, Code-behind should be used only as an aid to the interface (View), without business logic and control Code.

What is the difference between V in MVP and V in MVC?

In MVP, V is a simple packaging of the interface (it must be simple to not involve logic issues). In MVC, V is completely passive.

MVC Class Structure

The purpose is to separate as many functions as possible from the asp.net runtime, that is, to break down the role of Page into several classes:

View: displays data,Delay user input and triggered eventsPresenter.

An interface (Interface), Representing allViewThe background Code treats this interface as an interface without the needPage,System. webThis interface encapsulatesAsp runtime.

Both the interface and the background logic pass information through this interface.

Presenter: CoordinationViewAnd background services and business logic, responsible for page logic.POnly depends onIView,Modle(Recommended)FacadeMode, provides a middle layer, isolationModel).PThere cannot be too many functions,MVPMediumPGenerallyMVCOfCMultiple, but subdivided from functional aspectsPTo several classes is sometimes necessary, such as verification, paging, sorting, etc.PIt will not be very big and cohesive.

VKey points:

1,VMust depend on the InterfaceIview

2,IViewTo minimize the number of simplePOCOAnd encapsulate these attributes into classes or expose them.DTO, Or evenMOdle, Such

public interface IWorkItemView
        {
               // Packs the user input into a new WorkItem class
               WorkItem WorkItem{get;}
 
               // Sets the values in the dropdown list for the WorkItem assigned to user
               string[] AssignmentList {set;}
 
               // Sets the values in the dropdown list for the WorkItem categories
               string[] CategoryList {set;}
        }
public interface IWorkItemView
        {
               string AssignedTo {get; set;}
               string Category {get; set;}
               string Description {get; set;}
               string Priority {get; set;}
               string Comments {get; set;}
               
                /* More properties */
        }

 

PKey points:

1, ViewMultiple presenters are allowed.For example, a low-level ViewAnd ModelIng and verification. Another PresenterResponsible for business logic and background services

Not found

 

 

 

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.