Analysis of Three-tier architecture, analysis of three-tier architecture

Source: Internet
Author: User

Analysis of Three-tier architecture, analysis of three-tier architecture
Three-tier architectureLet's take a preliminary look at the three-tier architecture through several questions.
1. What is a three-tier architecture?
2. Application Scenario-why should we use a three-tier architecture?3. Role of layer-34. Relationship between layers5. layer-3 contact-Reference6. How to call each layer7. Comparison between Layer 3 and Layer 2These are the most basic problems in learning Layer 3. Only by clarifying these problems can we open the Layer 3 door.

1. What is a three-tier architecture?

In the software architecture design, hierarchical structure is the most common and important structure. The three layers are data access layer (DAL), business logic layer (BLL), and presentation layer (UI ).



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

Business logic layer (BLL): operations on the data layer and processing of data business logic.

Data access layer (DAL): database operations, data addition, deletion, modification, and search.


2. Application Scenario-why should we use a three-tier architecture?

Why should we use a three-tier architecture?

Decoupling!

Not all programs require a three-tier architecture, and there is no need to complicate the simple problem.

Let's talk about decoupling first, for example: computer repair

Is the hard drive on the computer broken? What we need to do is to replace the hard disk of the computer.

Memory is broken? Just change the memory.

Any problems with these components will not affect the normal use of other components. This is to decouple them. Different from computers, when any radio component is broken, it will affect other components. This reflects that the coupling between them is relatively high. From this example, we can see the benefits of decoupling. In the three layers, it is the idea of decoupling.

 

 

3. Role of layer-3

Data access layer: load data from the data source (Select), write (Insert/Update), Delete (Delete) data.Only dealing with data sources makes the program simple and clear.

Display layer (UI): displays specific business data to users and collects user input information and operations.

Principle: The user is the highest, and both are concise.

Business logic layer (BLL): obtains data from the DAL for UI display, and obtains user commands and data from the UI, execute business logic, obtain user commands and data from the UI, and write data to the data source through the DAL.

 

4. Relationship between layers:

UI-> BLL-> UI: the UI provides data commands to the business logic. If you can handle them yourself, you can directly report them to the UI.

UI-> BLL-> DAL: the UI provides user instructions and data, initiates requests, and collects certain data BLL. When BLL cannot process the data, access the data source, to DAL.



5. layer-3 contact-Reference

The following uses login as an example to describe the reference relationship between three layers:

Entity layer: defined username and password.

U layer: Enter the account and password in the corresponding text box

Layer B: determines whether the account and password entered at the U layer exist.

Layer D: The statement used to connect to the database and query the database.

The relationships between them are implemented through entity transmission ,.

 

The Assembly where DAL is located does not reference BLL and UI

BLL needs to reference DAL

The UI directly references DAL and may reference BLL.

We are very reluctant to quote each other. To avoid this problem, all entity layers (business data models, data and databases in these models are different)

Application Principles:

DAL only provides basic data access and does not contain any business-related logic. The UI is only responsible for displaying and collecting user operations, and does not contain any business-related logic processing. BLL is responsible for processing the business logic. By obtaining operation instructions from the UI, it decides to execute the business logic, the data source is directly accessed by DAL. After the processing is complete, the necessary data is returned to the UI.

 

6. How to call each layer

The presentation layer (UI) is the interface required by the user. All user requirements are modified on this page. Once there are changes, the U layer first sends a description of the user request to the B layer, after arriving at Layer B, layer B sends user requests from the U layer to layer D. layer D receives the user request instructions and processes the requests. The data is sent back to layer B, layer B is then sent to the U layer to reflect this change.

 

Example:

For example, if you eat a mutton string for a dish or a bird, the dish and a bird are users, the waiter is the presentation layer (U layer), and the barbecue master is the business logic layer (the U layer references the method or parameters of layer B ), the proprietress is the data access layer (layer D) and is responsible for giving the barbecue master a kebab from the warehouse. The Big Bird ordered five (parameters) of the mutton string. The waiter passed the five (parameters passed) of the mutton string to the barbecue master (Data Request), and the barbecue master sent it to the wife of the boss (parameters are processed ), after receiving the request, the boss sent a mutton string to the barbecue master (data feedback). The barbecue master gave the roast mutton string to the waiter (data feedback ), the waiter then sends five strings of mutton to the laruence (the U layer is displayed), and they are connected by calling them.

 

7. layer-3 primary key layer-2 architecture:

The business logic is simple and there is no real data storage layer

Three-tier architecture:

Abstract The business logic layer. when the business is complex to a certain extent, when the data is stored in the corresponding storage medium, the data storage is separated from the business logic and the business logic is separated from the UI, the UI can interact with users by calling the business access layer.

Advantages of Layer 3:

1. developers can only pay attention to one of the layers in the entire structure;

2. It is easy to replace the original implementation with the new implementation;

3. The dependency between layers can be reduced;

4. conducive to standardization;

5. facilitate the reuse of logic at each layer.

6. Clearer Structure

7. In the later maintenance period, the maintenance cost and time are greatly reduced.

 

The central idea of these points is "High Cohesion and low coupling". the weaker the coupling between classes, the more conducive it is to reuse. A class with weak coupling is modified, does not affect related classes.

The above is a simple understanding of the three layers, some places may be wrong, please point out!

 


NET three-tier architecture 1: What is a three-tier architecture

The layer-3 architecture adds an intermediate layer between the client and the database, also called the component layer. The layer-3 system mentioned here does not refer to the layer-3 physical architecture, instead of simply placing three machines as the layer-3 architecture, or not just B/S applications as the layer-3 architecture, layer 3 refers to the logic layer 3, even if these three layers are placed on one machine. During project development, the entire project is sometimes divided into three layers, including the presentation layer (UI), business logic layer (BLL), and data access layer (DAL ). The role of layer-3 is as follows: Presentation Layer: provides an interactive operation interface for users. This is true for both Web and WinForm. The interface that our website displays to users. Business logic layer: responsible for key business processing and data transmission. Complex logic judgment and data verification involving databases must be processed here. Return the desired value or process related logic based on the input value. Data access layer: This layer is known and responsible for accessing database data. It mainly provides data for the business logic layer, and operates databases based on input values, such as adding, deleting, modifying, or other data. Below I will briefly introduce the next user management module: to facilitate the development of the entire project, we will create several Class Libraries SQLHelper, BLL, DAL, Model and a Web site in the project. To make the name clear, we can name the three projects (Class Libraries added in the solution) as follows: business logic layer: BLL, by default, the namespace is set to BLL data access layer (DataAccessLayer): DAL, And the namespace is set to DALSQL help class: SQLHelper. The namespace is set to SQLHelper by default. In addition, for the convenience of data transmission, we usually add another class library that runs throughout the three-tier architecture. Entity class. The namespace is usually named "Model" and the default value is "Models. Each encapsulated class corresponds to an object, which is usually a table in the database. For example, if the user table (custom) in the database is encapsulated as (custom), each field in the table is encapsulated as a common attribute. In this way, the construction of the three-tier architecture is basically complete. These three layers have a very strong dependency: The presentation layer refers to the business logic layer, the data access layer, the data transmission between them is bidirectional, and data is usually transmitted through the entity class. What are the advantages of the three-tier architecture? 1. It is easy to modify and maintain projects. During project development or after development, or even during project migration. This three-tier architecture is very convenient. For example, to migrate a project from Web to Form, we only need to repeat the presentation layer. The remaining two layers do not need to be changed. You only need to add them to the existing project. If this architecture is not used, the code is only written to the presentation layer. Then almost all the codes will be re-submitted. 2. Easy to expand. This is also true for function extensions. If a function is added, you only need to add the original class library. 3. Easy code reuse. This does not need to be explained. 4. Easy division of labor and collaboration. You can also add an interface class library Iinterface and add the design mode to make your code more flexible. In fact, when we are working on a project, we should first consider whether this project should be applied to a layer-3/multi-layer design. Should we first consider whether it is really necessary?

NET three-tier architecture 1: What is a three-tier architecture

The layer-3 architecture adds an intermediate layer between the client and the database, also called the component layer. The layer-3 system mentioned here does not refer to the layer-3 physical architecture, instead of simply placing three machines as the layer-3 architecture, or not just B/S applications as the layer-3 architecture, layer 3 refers to the logic layer 3, even if these three layers are placed on one machine. During project development, the entire project is sometimes divided into three layers, including the presentation layer (UI), business logic layer (BLL), and data access layer (DAL ). The role of layer-3 is as follows: Presentation Layer: provides an interactive operation interface for users. This is true for both Web and WinForm. The interface that our website displays to users. Business logic layer: responsible for key business processing and data transmission. Complex logic judgment and data verification involving databases must be processed here. Return the desired value or process related logic based on the input value. Data access layer: This layer is known and responsible for accessing database data. It mainly provides data for the business logic layer, and operates databases based on input values, such as adding, deleting, modifying, or other data. Below I will briefly introduce the next user management module: to facilitate the development of the entire project, we will create several Class Libraries SQLHelper, BLL, DAL, Model and a Web site in the project. To make the name clear, we can name the three projects (Class Libraries added in the solution) as follows: business logic layer: BLL, by default, the namespace is set to BLL data access layer (DataAccessLayer): DAL, And the namespace is set to DALSQL help class: SQLHelper. The namespace is set to SQLHelper by default. In addition, for the convenience of data transmission, we usually add another class library that runs throughout the three-tier architecture. Entity class. The namespace is usually named "Model" and the default value is "Models. Each encapsulated class corresponds to an object, which is usually a table in the database. For example, if the user table (custom) in the database is encapsulated as (custom), each field in the table is encapsulated as a common attribute. In this way, the construction of the three-tier architecture is basically complete. These three layers have a very strong dependency: The presentation layer refers to the business logic layer, the data access layer, the data transmission between them is bidirectional, and data is usually transmitted through the entity class. 1. Easy Project Modification and maintenance. During project development or after development, or even during project migration. This three-tier architecture is very convenient. For example, to migrate a project from Web to Form, we only need to repeat the presentation layer. The remaining two layers do not need to be changed. You only need to add them to the existing project. If this architecture is not used, the code is only written to the presentation layer. Then almost all the codes will be re-submitted. 2. Easy to expand. This is also true for function extensions. If a function is added, you only need to add the original class library. 3. Easy code reuse. This does not need to be explained. 4. Easy division of labor and collaboration. You can also add an interface class library Iinterface to the design mode to make your code more flexible. In fact, when we build a project, we should first consider whether this project should be applied to the layer-3/multi-layer design, first consider whether it is really necessary? In fact, it is enough for most programs to open a WebApplication, and there is no need to make such a complicated one. The multi-layer structure is used to solve the real complex project requirements.

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.