ASP. NET differences between the three-layer structure and the MVC Mode

Source: Internet
Author: User
Some friends in csdn and garden talked about the difference between Layer 3 and MVC. Some people have thrown this question before. I will also raise this question to my friends who come to the company for interviews.

Let me also talk about my understanding of the two.

First of all, there is a problem with this question. What is the difference between "XX structure" and "XX mode? What is the difference between Chinese social systems and American lifestyles?

The two talk about different directions and perspectives. in actual application, they do have some similar characteristics, and they have not been thoroughly explained in many books, which leads to confusion, to better understand them, let's talk about the difference.

First, the N-layer structure is a software abstraction hierarchy, which is a vertical segmentation of complex software. Each layer completes the same type of operations, in order to separate various codes based on their completed missions, so as to reduce the complexity of software and improve its maintainability. Generally, layers are down-dependent. Before the lower-level Code determines its interface (contract), the upper-level Code cannot be developed, and the lower-level code interface (contract) changes will make the upper-layer code change together. A layer-3 structure is a type of N-layer structure. It is a wide range of N-layer structures that are widely used by human production for a long time, it is widely used and even written into textbooks as a typical software hierarchy.

The MVC mode is a composite design mode. It is a solution that can be used to solve certain practical problems in a specific scenario and can be used repeatedly. Coincidentally, he also has three things. As a result, people have a natural correspondence: Display layer-view, business logic layer-control, and persistence layer-model. First, there is no obvious hierarchy between the three things in MVC and there is no obvious downward dependency. On the contrary, view and model are often relatively independent, control is a bridge connecting the two. They are more like horizontal splitting. As a result, every module in MVC can be tested independently. In the layer-3 structure, the running test of the upper module is bound to provide lower-level code or a pile with the same interface. Relatively speaking, MVC is much more complicated, but the structure is clearer and the coupling is lower.

In addition, each module in MVC, especially the internal model, is often designed as multi-layer. In my opinion, in a good structure built by MVC, control is the core, small and stable, and can be provided as a core framework with scalability, however, it can be simply configured and run without any code. The view may be a set of or multiple selectable view engines, which determine the interface on which the software is displayed, the main workload for use is the scaling point and the number of view templates that vary according to requirements.

A model is a service provider and determines the functions provided by the software. It may be a common class or a class that implements some interfaces, this section may be colorful based on different businesses and may be divided into multiple layers for complicated software, such as the business logic layer, business provision layer, system provision layer, data provision layer, and data access layer.

I often use the example of MVC to compare it with the card game machine that I played when I was a child. Control is a host. Generally, I can buy a host, as long as it is not bad, he can keep letting me play this kind of game. View is a TV set and game controller. The TV set can work independently. No matter whether it is a TV signal, a player signal, or a game machine signal, he just displays, and he decided what we saw. If I wanted a larger size or color display, I just needed to buy a TV set, the handle can also be changed. The remote pole must still be shaken. The model is a game card. He never decided what game I was playing, whether it was Soldado or super Mary, in addition, game machine hosts and TV manufacturers never know what kind of games they might run on them. There may be game code and storage units in the card band, all of which are designed based on the needs of the game.

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.