How do you understand MVC?

Source: Internet
Author: User

Recent Academic Exchange conferences are studying MVC, holding a good study, the psychological, every now and then to rub the meeting. To tell the truth, I have seen some of the relevant data of MVC, but just a little bit. And, because the first three layers, so look at MVC, the subconscious feel that they are a thing. But MVC is MVC, layer three is layer three. The following will show the results of last night's academic exchange meeting and the way we discussed it. If there are shortcomings, also hope to criticize correct!


Layer three is divided into U (interface layer), B (business logic Layer), D (data access layer), which is our first layered thought. After learning three levels, we were exposed to MVC, and it was natural for us to compare MVC with layer three. However, after the comparison, there are two results, see the following:


Wrong opinion one:

Some people directly equate the three layer's U layer with the MVC view + Controller. The BLL layer + DAL layer is equivalent to Model.


Right point of view one:

The BLL layer consists of two parts: one is IBLL, which is the abstraction of the interface part, defines what to do? The second is the BLL, that is, the detailed implementation of the section, define how to do? And controller is the control of the meaning, it is responsible for forwarding to which view and command what to do (business)? Detail how to dry without it tube. So actually controller = part of U + IBLL. Model = Container for "BLL (Implementation part) + DAL": Objects and operations. View is only responsible for displaying data results.


Wrong opinion two:

The business divide is correct, and the call relationship between MVC is the same as the three layer.

Three-layer call relationship:

1.U, B, D layer from top to bottom, lower level for the upper service;

2.U, B, D equal Relations, U layer can not leapfrog jump to the D layer.


Right opinion two:



Improves the controller's position in the MVC system. C is the central link between the view and the model to communicate with each other. The view and model are not likely to communicate without the permission of the controller. In other words, only the controller allows the view to change the data to the Model,model, and it can be notified to the view. Controller master the changes between view nodes and the operation of objects in the model layer.

corresponding to our Java Web, C is equivalent to a servlet, model equivalent to a Java Bean, View is equivalent to a JSP. The browser sends the request directly to Servlet,servlet to accept the data to go to the model layer to process, and finally the servlet forwards the saved results to the JSP page, and the data is displayed by the JSP page. This shows that the servlet can correspond to multiple JSP pages.


To the full extent of the complaint:

MVC has undergone a radical change in structure and differs from layer three. Such changes have brought great advantages to a certain extent.

  1. Efficiency increased, three layer is a strict call relationship, transmission or reading data, the need to go through layers of calls, talent to obtain data. Efficiency has been greatly reduced. The view and model are able to communicate and transmit faster.
  2. Decoupling, the user and data operations are completely isolated under the controller's unified management.
  3. Flexibility is greatly improved, and controller is able to manage multiple view so that when the view changes, it can be changed arbitrarily.


Summarize:

The understanding of things is a step-by-step process of deepening. Each step of deepening may let us overthrow ourselves, but this does not mean that we are wrong in the front. The deepening of this understanding must be based on the view that we have overturned. So, knowing that there is no right or wrong point, just say under what conditions, will have what kind of understanding.


How do you understand MVC?

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.