Simple understanding of MVC

Source: Internet
Author: User

Simple understanding of MVC

To learn a new knowledge, you must first understand the following questions: What is it? What can it do? What are the benefits of using it? This article will discuss these issues.

Mvc is not a programming language. Strictly speaking, it is not a technology. It is an "Architecture (framework)" used in software development )". It is like a development mode or a program design template.

Software developers often talk about changes in the software development process. The demand changes, the technology changes, the customer changes, the boss changes, and the pain point is that the PM changes, nothing remains unchanged during the development process. changes will bring great changes to software development. We cannot change these changes. The only thing we can do is to minimize the losses caused by changes, mvc is one of the solutions.

MVC and Model View Controller are short for models, views, and controllers. They are a Model that separates the interface display, business logic, and data, in this way, you can modify the interface display without changing the logic. Reduces the coupling between the interface and logic functions, and increases code reuse.

The Model layer, also known as the Model layer, is mainly responsible for data interaction tasks. The main functions of the model layer include defining data structures, reading data from databases, obtaining data, verifying data formats, and reading data for processing. The model layer is similar to the DAL layer in the three-tier architecture. It interacts with the database and performs simple data processing.

The View layer, that is, the View layer, is responsible for all interface layer tasks, in fact, writing data and displaying data. The main functions are to obtain data, display data, determine the interface technology (HTML, XML, Flash, etc.), interface layout; return data to the Controller, determine the data transmission mode, data verification. The view layer is similar to the UI Layer in the third layer, mainly for data interaction with users.

The Controller layer and the set control layer accept user input data and call models and views to meet user requirements. When a user clicks a hyperlink or sends an HTML form, the controller does not actually process or output any data. It only determines which model or view to call to process the request according to the actual situation, then decide which view to use to display the returned processing result. The BLL layer in the Controller layer is different from the BLL layer in the layer 3 because it does not have data processing or logic processing functions. It only controls the call of other components to fulfill the requirements.

Let's look at a simple page display example:

First, the page responds to user events, and then sends user requirements to the controller. The controller calls the model component according to user requirements. The model component completes data operations and then returns the result to the controller, select the corresponding view to display the result to the interface.

As you can see, the controller completely separates the interface display and data processing, reducing the coupling between them. developers can change the interface display as needed without considering the data processing function, in this way, the coupling of the system is very low, and the lower-layer code reusability is increased.

Comparison with Layer 3:

It can be seen that mvc is very different from the three layers. The three layers are divided to solve code encapsulation problems at different stages in the software development process. The Division of layers increases the flexibility of the system, reduced the system coupling (not completely resolved ). The three-tier architecture can be applied in all software development. Mvc separates page display from business logic to solve the page change problem. mvc places all page display in view and encapsulates data operations and processing into model, controller for overall control. Mvc is designed to solve the problem of interface display and business logic coupling in BS projects.

Conclusion: MVC and Layer 3 are designed to reduce system coupling, but they have different focuses. They are not good or bad, but they are suitable for problems that are not suitable for solving this problem or whether they can be used properly.

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: 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.