asp.net mvc (pattern) and three-tier architecture (BLL, DAL, model) and the difference between

Source: Internet
Author: User
First, MVC and the three-tier architecture are different.
In the three-tier architecture, the DAL (data access layer), the BLL (business Logic Layer), the Web layer perform their duties and are intended to separate responsibilities.
MVC is Model-view-controller, strictly speaking, these three add up after the three-tier architecture Web Layer, that is, MVC has again differentiated the web layer in the three-tier architecture, divided into the controller, view, entity three parts, the controller completes the page logic, through the entity to complete the call with the interface layer, while the C-level directly with the BLL in the three-level dialogue.
So, in the three-tier structure of. NET, there is no action in this concept.
asp.net mvc is a new Web development architecture launched by Microsoft. In order to solve the traditional ASP.net development can not separate Model,view and controller design.
Ordinary Web site in order to solve the problem of portability, maintenance, scalability and so on, will be the site design into three separate modules, model is responsible for the database section, view is responsible for the Web page interface, and controller is responsible for interface and data interaction and business logic, This design of the site if you want to design or redevelopment of a module on the other modules are not affected. But ASP.net's page background code is one by one corresponding to each page code, and the business logic is inevitably written to the background code associated with the view in some cases. This can not guarantee the view and controller separation, it is difficult to achieve the site's rewriting and upgrading.
In MVC, the page code does not correspond to the background code one by one, but is stored into controller and view two parts, completely solved, view and controller can not be independent of the problem. Thus improving the site's rewriting and upgrading process.
But MVC also has its drawbacks, because it is no longer possible to use server controls in the page code, causing problems with the use of certain ASP.net server-side controls, and MVC also poses many hurdles to the design of the page.
ASP.net MVC is a new Web development architecture that Microsoft released in April 2009, Http://msdn.microsoft.com/en-us/library/dd394709.a SPX, It is the traditional sense of MVC development thought into the development of asp.net.
So let me also say my understanding of the two.
First on this topic, itself is a problem, "XX structure" and "xx mode" difference. What is the difference between Chinese social system and American way of life?
The two themselves speak of different directions and angles of the problem, in the actual application they do exist some similar characteristics, in many books also did not in-depth explanation, so as to create confusion, in order to better understand them, let's say the difference.
First n-tier structure is a software abstraction hierarchy, is a vertical segmentation of complex software, each level to complete the same type of operation, so that all kinds of code to its completion of the mission as a basis for segmentation, to the complexity of low software, improve its maintainability. In general, the hierarchy is down-dependent, the underlying code does not determine its interface (contract) before the upper layer of code is not developed, the underlying code interface (contract) changes will make the upper layer of code changes. Three-layer structure is a kind of n-layer structure, is a human production in the long time use of a wide range of n-tier structure, as a typical software hierarchy and widely circulated or even written textbooks.
The MVC pattern is a composite design pattern, a solution that can be repeatedly practiced in a particular situation to solve a practical problem. Coincidentally, he also has three things, so people have a kind of assumption of the corresponding relationship: the presentation layer-view; business logic layer-control; persistence layer-model. First of all three things in MVC there is no obvious hierarchy, there is no obvious downward dependency, on the contrary, view and model are often relatively independent, and control is the bridge between the two, they are more like horizontal segmentation. As a result, each block in MVC can be tested independently, and in a three-tier structure, the running test of the upper module is bound to provide low-level code or piles that provide the same interface. In contrast, MVC is much more complex, but the structure is clearer and the coupling is lower.
In addition, each piece within MVC, especially inside model, is often designed to be multilayered. In a structure that I think is a good MVC pattern, control is the core, small and stable, and can be provided as a core framework, with extension points, but basically it can be simply configured to run without requiring any code. The view may be one or more options for the viewing engine, which determines what the software is shown to be used for, and the main workload when used is the extension point and the number of different view templates as needed. Model is the business provider, determines the function provided by the software, the interior may be a common class or a class that implements some interfaces, which may be colorful depending on the business, and may be divided into many layers for complex software, such as business logic tier, business delivery tier, system delivery layer, data supply layer , data access layer, and so on.
I often use the analogy of MVC as an example of the same kind of cassette game machine, control is the host, generally I buy a host on the line, as long as he is not bad, he can always let me play this kind of game. The view is the TV and the game handle, the television can work independently, regardless of whether the input is the television signal, the player signal or the game signal, he just shows, and he decided we see how the effect is, if I want a larger size or color display effect, I just need to buy a corresponding TV set, the handle is also can be changed, to distance the pole or with vibration. Model is a game cassette, he absolutely decided what I play is the game, is the Soul Dou Luo or Super Mary, and console consoles and TV manufacturers will never know what the above may run what kind of game. There may be game codes and storage units in the cassette that are designed to suit the needs of the game.
A friend mentions the interface of the cassette slot provided by the game host, in the design, sometimes also by the control provides a set of interfaces for model or view implementation, thus forming a dependency. In general, this design is not too much problem, but will improve the coupling between the modules, but also bring some intrusion. To be perfect, you can provide a contract without an interface, you can use configuration information (or metadata information) + reflection to provide a contract, then this class interface can be degraded to as long as CLS-compliant, that is, ordinary classes, like the current computer interface widely used USB, whether it is USB disk, printer, Scanners or cryptographic dogs, they are all ordinary USB devices.
Mentioned that USB has a digression, the module's pluggable design is even hot-swappable design, the system can dynamically mount or remove the module without stopping operation, the dynamic Mount module needs the system to automatically discover the new module and automatically configure it according to the self-describing information, remove the possible situation more complicated, need " Secure removal of hardware "similar functionality.

When designing a broadly reusable framework, multiple scenarios are taken into account to achieve greater adaptability, and the MVC pattern can be used more freely in general projects.

So, you can simply use a code generator to generate a three-tier architecture that replaces the Web layer with the MVC pattern, like this:


Related Article

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.