Layer-3 learning ------ theory

Source: Internet
Author: User

The school has a holiday, and the child who just returned home is like a guest hosted by his parents. A few days before the holiday, despite opening your mouth, your parents will satisfy you if you want to eat anything! In my house, the kitchen is my mom's place. I buy food, cook, and cook a pot. It's all-inclusive. While there are many people who eat at restaurants, and the types of meals ordered by customers vary. There is a division of labor in the hotel because of the busy work of a person. The front-end waiter is responsible for reporting the food ordered by the customer to the cook and the cook cooking according to the reported menu, and the buyer is responsible for the tea containing rice, oil, salt, and soy sauce. In this way, everyone performs their respective duties in a well-organized manner.

It is relatively simple to eat at home without a specific division of labor. A hotel is a complicated and huge system, which requires reasonable planning and clear division of labor. An excellent software system must first have a good framework. A good architecture can achieve high cohesion and loose coupling, thus improving software scalability, reusability, maintainability, and flexibility. In the software architecture, the layered structure is the most common and important one. The hierarchical structure recommended by Microsoft is generally divided into three layers: presentation layer, business logic layer, and data access layer. See a picture below to link the hotel with a three-tier structure to integrate learning into life.

Database server. Next, let's take a look at these three layers.

Presentation layer (UI ):Collect User input information and operations to show specific business data to users. In general, it is the user interface, that is, what a user sees when using a system.

Business logic layer (BLL ):Operations for specific problems can also be called operations on the data layer and data business logic. There are three main methods: Getting user instructions and data from the UI and executing business logic; getting data from the DAL for UI display; getting user instructions and data from the UI, write Data sources through DAL.

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


There is also an entity layer (class), which jumps up and down between the three layers. by analogy in the chenyang blog, this entity layer is like a letter, layer B is the contact person who transmits the letter between the U and D layers. He does not know the content of the letter.

In these three layers, DAL only provides basic data access, and the UI is only responsible for displaying and collecting user operations. They do not contain any business-related logic processing. BLL is responsible for processing the business logic. By obtaining operation commands from the UI, it executes the business logic and hand it over to the DAL for processing when the data source needs to be accessed. After the processing is completed, the necessary data is returned to the UI. UI references BLL and BLL references DAL, which can be referenced from top to bottom, which in turn won't work. All three layers can reference the entity layer (class), but the entity layer cannot reference other layers.

There are many advantages of using Layer 3. developers can only focus on a layer in the entire structure, which facilitates division of labor and collaboration and reduces dependencies between layers. When a layer needs to be changed, it does not affect other layers, reducing maintenance costs and maintenance time. When different business needs call the same data table, the same code only needs to be written once. This facilitates the reuse and standardization of logic at each layer, and achieves high cohesion and loose coupling of software systems. One coin has two sides. The disadvantage of doing so is that the middle layer is added and the database cannot be accessed directly, thus reducing the system performance. Sometimes it may lead to cascade modifications. If you need to add a function in the presentation layer, to ensure that the design conforms to the hierarchical structure, you may need to add the corresponding code in the business logic layer and data access layer. Of course, it also increases development costs. In actual software development, we need to analyze the specific situation and weigh the advantages and disadvantages.



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.