About the three-tier architecture

Source: Internet
Author: User

1, What is layer three?

UI ( presentation layer ): mainly refers to the interface that interacts with the user . Used to receive data entered by the user and to display the data that the user needs after processing.

BLL: ( business Logic Layer ): A bridge between the UI layer and the DAL layer . Implement business logic . Business logic includes: validation, calculations, business rules, and so on.

DAL: ( data Access layer ): dealing with Databases . The main realization of the data increase, delete, change, check. Submits the data stored in the database to the business layer, while saving the data processed by the business layer to the database. (These operations are, of course, based on the UI layer.) The user's needs are reflected to the interface (UI), the UI is reflected to the BLL, the BLL is reflected to the dal, thedal is manipulated for data, and one by one returns after the operation. Until the user's desired data is fed back to the user)

Waiter : just receive the guest;

chef : Just do the dishes that the guests ordered;

buyer : just buy the ingredients according to the order of the guests;

They each take their place, the waiter does not need to know how cooks Cook, do not know how the buyer buys the ingredients; The chef does not need to know which guest the waiter received, do not know how the buyer buys the ingredients; Similarly, the buyer does not need to know the waiter who received the guests, do not know how cooks cook dishes.

How are the three of them connected?

For example: Cook will do: fried eggplant, scrambled eggs, fried noodles-at this time to build three methods ( cookeggplant (),Cookegg(),cooknoodle ())

The customer and the waiter, the customer and the waiter (UI layer) said: I want a fried eggplant, and the waiter is not responsible for fried eggplant, she put the request to submit, passed to the chef (BLL layer), the chef needs eggplant, the request to submit, Passed to the buyer (DAL layer), the buyer from the warehouse to take the eggplant back to the chef, cook response to cookeggplant () method, cooked eggplant, and returned to the waiter, The waiter presented the eggplant to the customer.

This completes a complete operation.

In this process, the eggplant is passed as a parameter in the three layer, if the customer points scrambled eggs, then the egg as a parameter (this is the variable parameter). If, the user increases the demand, we also have to add the parameter in the method, one method adds one, one method designs to three layers, moreover actually does not have to design to one method the change. Therefore, in order to solve this problem, we can be the eggplant, eggs, noodles as a property definition to the customer entity, once the customer increased the demand for scrambled eggs, directly put the attributes of the eggs can be used, do not have to consider the method of each layer to add parameters, not to mention the parameter matching problem.

2 , why use three layers?

Purpose of using three-tier architecture: Decoupling!!!

Also take the example of the restaurant above:

(1) Waiter (UI layer) Leave--Find another waiter; the chef (theBLL ) resigns-recruiting another chef; the buyer (DAL) resigns-recruiting another purchaser;

(2) customer response:1> You shop service attitude is not good--waiter's problem. Dismissal of the waiter;

2> you have bugs in your shop--the chef's problem. Change the chef;

3, three-tier architecture advantages and disadvantages

Advantages: 1, the structure is clear, the coupling degree is low , 2, the maintainability ishigh, the expansibility is high,3, is advantageous to thedevelopment task to carry on synchronously; easily adapts to the demand change

Disadvantage:1, reduce the performance of the system. This is self-evident. Without a tiered structure, many businesses can access the database directly to get the data, and now they have to do it through the middle tier.

2. Sometimes cascade changes are caused. This kind of modification is especially reflected in the top-down direction. If you need to add a feature in the presentation layer to ensure that the design conforms to the layered structure, you may need to add code to the appropriate business logic layer and the data access layer

3, increase the amount of code, increase the workload

4, three layer architectural representation

Ui:

(1, function: User input data, feedback to user data;2, We observe the code : No business logic involved, direct parameters, functions, method calls, not related to the database dealing with SQL statements and ADO)

BLL:

(1) The BLL is the bridge between the presentation layer and the data access layer, which is responsible for data processing and transmission;2, we observe the code, there is no interface to the control, no related to SQL statements and ADO)

DAL:

(1, There is no interface control, no business logic involved; only SQL statements that deal with databases and ADO )

Entity(Model) layer:

(defines the entity class user)

Observe above three layers:

1, the entity class user as a parameter throughout the three layers;

2, through the transfer of parameters, method calls to achieve the function;

3, accountability between the layers; non-impact

(EXT) about the three-tier architecture

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.