Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the working principle of web three-tier architecture

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the working principle of the three-tier architecture of web". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the working principle of the three-tier architecture of web".

First, what is the three-tier architecture

The three-tier architecture is in line with the idea of "high cohesion and low coupling". Each functional module is divided into three layers: presentation layer (UI), business logic layer (BLL) and data access layer (DAL). Each layer accesses each other through interfaces, and the entity classes of the object model (Model) are used as the carrier of data transmission. The entity classes of different object models generally correspond to different tables of the database. The properties of the entity class match the field names of the database table.

Functional division table of each module: UI (presentation layer) mainly refers to the interface that interacts with the user. It is used to receive the data input by the user and display the data needed by the user after processing. BLL: (business logic layer) the bridge between the UI layer and the DAL layer. Implement business logic. Business logic includes: validation, calculation, business rules, and so on. DAL: (data access layer) dealing with databases. It mainly realizes the addition, deletion, modification and query of the data. The data stored in the database is submitted to the business layer, and the data processed by the business layer is saved to the database. (of course, these operations are based on the UI layer. The user's needs are reflected to the interface (UI), and the UI is reflected to the BLL,BLL to respond to the DAL,DAL for the operation of the data, and then gradually return after the operation, until the data required by the user is fed back to the user) the operation flow chart of the three-tier architecture:

How to connect the functional modules in the three-tier architecture?

Entity (physical layer) is mentioned here: it does not belong to any of the three layers, but it is an essential layer. For a large amount of data, it is a bit complicated to use variables as parameters, because there are too many parameters and it is easy to get confused. For example: I want to pass the employee information to the lower level, including: employee number, name, age, gender, salary. If we use variables as parameters, then there will be a lot of parameters in our method, and it is very likely to confuse the parameter matching when using it. At this time, if you use the entity as a parameter, it will be very convenient, without considering the problem of parameter matching, it is convenient to use which attribute in the entity can be used directly. This also improves efficiency.

The role of Entity in the three-tier architecture: 1. Realize the "encapsulation" in the object-oriented thought; 2. It runs through the three layers and transfers data between the three layers; (note: specifically, the entity layer runs through the three layers to connect the three layers)

3. For beginners, it can be understood like this:

Each data table corresponds to an entity, that is, the fields in each data table correspond to attributes in the entity

(note: of course, this is not the case.

Why?

1 >) maybe the entity we need does not exist in the corresponding entity of the data table

2 >) We can put all the fields in all the data tables in one entity)

4. The data transfer (one-way) between each layer (UI- > BLL- > DAL) depends on variables or entities as parameters, so the relationship between the three layers is constructed and the function is realized.

(add: 3. Why can it be temporarily understood that each data table corresponds to an entity?

The purpose of our system is to provide services for users, users do not care about how your system background works, users only care about whether the software is easy to use and whether the interface is in line with their own wishes. Users can easily add, delete, change and check in the interface, then there should be corresponding additions, deletions, changes and queries in the database, and the specific operation object of adding, deleting, changing and checking is the data in the database, to put it bluntly, the fields in the table. Therefore, each data table is treated as an entity class, and the attributes encapsulated by the entity class correspond to the fields in the table, so that when the entity runs through the three layers, it can add, delete, modify and check the data.

The dependency between the three layers and the physical layer:

Second, why to use the three-tier architecture

The purpose of the three-tier architecture is to distinguish between layers for "high cohesion, low coupling". Developers have a clearer division of labor, focus more on the analysis, design and development of the core business logic of the application system, speed up the progress of the project, improve the development efficiency, and is conducive to the update and maintenance of the project.

Third, the difference between three layers and two layers.

Two layers:

(when there is a change in any place, the whole system needs to be redeveloped. "Multi-layer" on one layer, the division of labor is not clear and the coupling degree is high-- difficult to adapt to the change of demand, low maintainability and low expansibility)

Three floors:

(for changes that occur in which layer, you only need to change that layer, not the entire system. Clear hierarchy, clear division of labor, low coupling between each layer-improved efficiency, adapting to changing requirements, high maintainability and high scalability)

The advantages of three-tier architecture: 1. The structure is clear and the coupling degree is low. High maintainability and high expansibility. It is conducive to the synchronization of development tasks, and it is easy to adapt to the disadvantages of three-tier architecture: 1. The performance of the system is reduced. This is self-evident. If we do not use the hierarchical structure, many businesses can directly visit the database to obtain the corresponding data, but now it must be done through the middle tier. two。 Sometimes it can lead to cascading changes. This modification is particularly reflected in the top-down direction. If you need to add a function in the presentation layer, in order to ensure that its design conforms to the hierarchical structure, you may need to add the corresponding code 3. 3 in the corresponding business logic layer and data access layer. Increased the amount of code, increased the workload thank you for reading, the above is "what is the working principle of web three-tier architecture" content, after the study of this article, I believe that you have a deeper understanding of what the working principle of web three-tier architecture is, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 229

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report