Presentation Layer Mode-MVC

Source: Internet
Author: User
Tags require

In the previous overview, from the service layer to the data tier see Schema Design directory. Left the performance layer, a good middle-tier performance must have a user interface, provide and user interaction, the user's behavior input into the system operation, into the background logic. With the support of the RAD (Rapid Application Development) tool, we can quickly finish the UI design, and RAD will pursue the quick feedback and fast application of WYSIWYG. The presentation layer also has its own fixed logic (formatting, data binding, transformation, etc., called UI logic) and interface presentation. UI logic here refers to all the logic used to process data displayed in the UI interface, and the logic of translating UI user input behavior into middle-tier directives, which is responsible for the transformation of UI and middle-tier data flow and behavior. Most of the time the UI is the easiest and most difficult to test logic (I've always believed that 1: a good piece of code must be easy to test.) 2: The premise of refactoring must also have sufficient testing to ensure that our refactoring is more rhythmic and more confident, but most of the UI logic is often more stable. This Matin Fowler presents the separation of the presentation layer model. The presentation layer model is divided into 3 major categories: MVC,MVP,PM (Microsoft in SL and WPF named MVVM), these 3-class models extend many variants of MVC in the Web Model2 (asp.net mvc, the main feature based on web-specific URI routing). Variant of the MVP: Passive view (passive view) and supervising Controller (not sure how to translate better), PM extended MVVM. The goal is to separate the changeable view and the UI logic.

Today is about MVC (Model-view-controller: Model-View-controller). In the beginning we say structure and programming or object-oriented principles are designed to achieve high cohesion and low coupling of modules, while cohesion well-structured classes coupling is an effective way to isolate the focus (SOC). To achieve the separation of performance UI and presentation logic, they are more flexible and autonomous views (classes that contain all the presentation layer code). The MVC model proposed by Trygve Reenskaug more than 30 years ago, or rather exemplary. Its performance layer is divided into 3 categories: Model: The view display data, view user interface, Controller: the user input into the middle-tier operation.

Model: In MVC, the model maintains the state of an application and changes in the state of the corresponding view from user interaction. In the above figure we can see the state change response of the controller and the display state of the view to query the data source of views rendering. At the same time model also has through the event mechanism (Observer mode) to notify view state changes require view rendering response. There is a certain coupling between view and model, and view must understand model, which is one of the reasons why the MVP pattern appears. Model models here can be either a distributed soap or a resetfull dto (data Transfer object), or a data set that is directly returned by our domain object (do) or data tier, and is not strictly required.

Controller (Controller): The controller is also view trigger, respond to the user interface interaction, and according to the performance layer logic change model state, as well as the interaction between the middle layer, the final modification Model,controller will not care about the rendering of the view, is by modifying model, Model's event notification mechanism, triggering the refresh rendering of the view. The interaction of a controller and a model is a "send or forget" or a distributed oneway call. Controller Controller does not actively understand view and view interactions, except for the unique view selection, the controller needs to choose what view is next displayed. The general controller requests that the global application route the next view that needs to be displayed, rendering it.

View: The reason that the presentation layer pattern appears when the view, because of his diversity and the frequency of change, not easy to test (too many external environment dependencies), so the ideal view should be as dumb and passive as possible, the view is only responsible for rendering rendering to user interaction. The view is composed of a number of column GUI components that trigger the controller logic in response to user behavior and modify the model state to keep the view synchronized. View and need the corresponding model changes passively accept model state change refresh corresponding to the user.

MVC first sprang up on the desktop, but it didn't catch on, knowing that when the web sprang up, its variants Model2 in the Web, and Asp.nte MVC under. Net. Model2, the request will come from the client (browser), The server-side interceptor (asp.net HttpModule) is forwarded to the fixed controller according to the URL format request, calls the fixed action, modifies the action Squadron model State, selects the View,view and produces the latest model produced by the controller Html,css,js before Segment code, and output to the preceding segment rendering.

The biggest difference between Model2 and original MVC is that:

1: There is no direct dependency between view views and model models, and mode does not know that view also does not require event notification View,view also do not need to know Model,view operations are ViewModel (asp.net mvc viewdata container). 2: The controller displays the incoming view data to see, the corresponding user's action is not from view, but for the server-side application in front of the interceptor, capturing the URL and forwarding to the appropriate controller, has called the appropriate action method.

MVC is now often referred to as the MODEL2 mode in the Web. In the Model2 view is passive, dumb, and simple.

This article from the "Wolf" blog, please be sure to keep this source http://whitewolfblog.blog.51cto.com/3973901/923346

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.