From three-tier architecture to MVC

Source: Internet
Author: User

I have been studying the three-layer architecture and MVC over the past few days. I was very confused just a few days ago. I found N pieces of information on the Internet, read n people's views, and browsed several books and videos, I have a little clue over the past few days. However, everyone has their own opinions, and even some people's opinions are wrong (I also think some people's opinions are wrong ), let's talk about my understanding of them. I hope you can correct them.


First, the three-layer architecture, namely, the presentation layer (UI), the business logic layer (BLL), and the data access layer (DAL ). Each layer has its own responsibilities to complete different tasks and minimize communication between different layers. All cohesion is greatly reduced. The following figure shows the relationship between three layers after I have processed images in Baidu encyclopedia. It is like a sandwich biscuit. The top-level biscuit is an appearance, and the lower-level biscuit plays an indispensable supporting role. The middle cream connects the upper and lower layers, complete their interaction.




So what are the three layers doing?

1,Presentation layer (UI): In general, it is the interface displayed to the user, that is, what the user sees when using a system.

2,Business logic layer (BLL): Operations for specific problems can also be called operations on the data layer and data business logic.

3,Data access layer (DAL): Transactions made at this layer directly operate on the database, and add, delete, modify, update, and search data.

 

Three Layers complicate simple problems. All the friends who have used three layers of projects know that a project with three layers of architecture is larger than a project without three layers of code. Why do they need to be layered?

Let's talk about the advantages of Layer 3:
1. decoupling. The previous layer only depends on the next layer. If there is no problem with the next layer, the problem may only occur at this layer. It is easy to detect and correct bugs.
2. simplify complex problems. For example, the layer-4 model of the TCPIP protocol or the OSI Layer-7 model, with clear division of labor at each layer, simplifies a complicated problem.
3. Easy System Maintenance/upgrade. The layers are decoupled through interfaces, and interfaces and implementations are separated, so that the implementation can be easily replaced or upgraded.
4. Logic reuse. For example, if a program originally developed based on B/S needs to be changed to C/S, the business layer and data layer can be reused as long as the business layer interface is not changed. For example, as long as the interfaces at the data access layer remain unchanged, different databases can be implemented.
5. Easy for team development. As long as the layers of interfaces are well defined before development, the layers can be independently developed, evolved, or maintained.
6. easy deployment. You can deploy layers independently by developing them into components.


In fact, not all layers are divided into three layers. If you want to, you can get more and get less layers, the complexity of the software increases accordingly, which is hard for others to understand and is also difficult to maintain. Products that are easy to maintain must be easy to understand. Maintenance is just a product that comes with it.

 


There are so many layers. Let's talk about MVC below. In fact, MVC and Layer 3 are not one thing. Many of my friends have mixed the two together. They are indeed very similar, but they are not one thing, just like making you compare the socialist system with the European Union.


MVC is short for "Model-View-controller". It is translated into "Model-View-controller" in Chinese ". View is the interface view, so we are easy to confuse with the three-tier architecture. The layer-3 architecture is responsible for each other. Everyone only cares about their own tasks and does not care about how others implement them. No one is willing to do anything that is related to each other, therefore, MVC is applied in the middle of them (between the UI Layer and BLL layer), just as the meaning expressed in the figure below by Lao Zhao (senior Microsoft Lecturer, Zhao Yu.



All of the above are my personal opinions, and I sincerely hope that you can put forward different opinions and opinions.




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.