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 MVC information, but just a little bit. And, because you learned three layers first, so when you look at MVC, subconsciously think of them as a thing. But MVC is MVC, layer three is layer three. We will show you the results of last night's academic Exchange conference 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 the layered thought we first approached. After learning three levels, we were exposed to MVC, when we naturally compared the MVC with the three layers. However, the following two results appear, as shown in the comparison:


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.


Correct view:

The BLL layer consists of two parts: the first is IBLL, which is the abstraction of the interface part, defines what to do? The second is the BLL, that is, the specific implementation of the part, 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)? Exactly how to do 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.


Now let's look at the right MVC



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. Without the controller's permission, view and model would not be able to communicate. In other words, as long as the Controller agrees, view can change the data to Model,model and can also be notified to view. Controller master the changes between view nodes and the operation of objects in the model layer.

In our Java Web, C corresponds to a servlet, model equivalent to a Java Bean, and a View 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. This change has brought great benefits to a certain extent.

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


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.


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.