Layer-3 development divides the entire business application of the system into the presentation layer-business logic layer-data access layer, which is conducive to system development, maintenance, deployment and expansion.

Source: Internet
Author: User

1. What is a three-tier architecture?

Layer-3 development divides the entire business application of the system into the presentation layer-business logic layer-data access layer, which is conducive to system development, maintenance, deployment and expansion.

Layering is to achieve "High Cohesion and low coupling ". The idea of "divide and conquer" is used to separate and solve problems, which is easy to control, extend, and allocate resources.

 

 

  • Presentation Layer: responsible for directly interacting with users, which generally refers to the system interface for data entry and data display. This means that only the work related to the appearance and display is required.

  • Business logic layer: This layer is used for validation to better ensure program running robustness. Such as adding, modifying, and querying data. You are not allowed to enter an empty string in the specified text box, check whether the data format is correct and the data type is verified, and check the validity of your permissions, based on the above judgment, you can determine whether to continue the operation and ensure the normal operation of the program as much as possible.

  • Data access layer: As the name implies, it is used to interact with databases. Add, delete, modify, and display data. It should be emphasized that all Data objects are referenced only at this layer, such as System. Data. SqlClient. Such references should not appear anywhere except the Data layer.

ASP. NET can use the. NET platform to quickly and conveniently deploy a three-tier architecture. ASP. NET revolutionary change is the use of event-based processing in the web page, you can specify the background code file to be processed, you can use C #, VB, C ++, and J # As the background code language .. NET, and the background Code uses namespaces to conveniently use custom components. The display layer is placed on the ASPX page, and the database operations and logic layer are implemented using components or encapsulation classes. This facilitates the implementation of the three-tier architecture.

2. Why is the layer-3 architecture used?

For a simple application, when the amount of code is not large, the development of a layer-2 structure or layer-2 structure is sufficient, and there is no need to complicate it, design is a layer-1 structure or layer-2 structure development, so such a design has very serious defects. As described below, hierarchical development actually serves large systems.

During the development process, junior programmers often copy code with similar functions. Why do they need to write the same code so many times? Not only does the program become lengthy, but it is not conducive to maintenance. A small modification may involve many pages, which often leads to exceptions that make the program unable to run normally. The most important Object-oriented thinking has not been fully reflected, but it still faces the process-oriented path under the guise of object-oriented.

Aware of this problem, the novice program personnel began to write some common processing programs in the program into public methods and encapsulate them in the class for other programs to call. For example, you can write a data operation class to properly encapsulate data operations. During database operations, you can complete specific data operations as long as the corresponding methods in the class (such as adding, modifying, and querying data, this is the data access layer. You do not need to write repetitive database operation code every time you operate the database. In new application development, the data access layer can be used directly. The encapsulation of one of the three main characteristics of Object-oriented has been well reflected here. Now, the reader seems to have found the object-oriented feeling. The amount of code is greatly reduced, and the modification is convenient, and the code reuse is also realized.

The following are two examples to explain why a three-tier architecture is used.

Case 1:

The database system software changes the database from Access to SQL Server due to the increasing data volume. As a result, the original data Access layer becomes invalid and the data operation object changes, in addition, you must modify the data objects on the page, because the OleDbDataReader object may be used to pass data to the display page. Now, you must replace it with the SqlDataReader object, the data types supported by SQL Server and Access are also different. Data conversion during data display must also be modified.

Case 2:

Due to special circumstances, how many modifications need to be made to transform a Web project into a Windows application? If Aspx. cs occupies a large amount of code or some code exists in Aspx, do you need to re-develop the entire system?

 

In the above case, have you realized the defect of no hierarchical development mode? Have you ever encountered such a situation? This is caused by unreasonable design. The emergence of multi-layer development architecture can solve this problem well. The rational hierarchy of the program architecture will greatly improve the universality of the program.

3. Advantages of three-tier architecture development

Three-tier architecture development has the following advantages:

  • From the perspective of development and application, the three-tier architecture has a greater advantage than the two-tier architecture or one-tier architecture. The three-tier architecture is suitable for team development. Each person can have a different division of labor. collaborative work doubles the efficiency. When developing a layer-2 or single-layer application, each developer should have a deep understanding of the system and have high capability requirements. When developing a layer-3 Application, you can combine multiple talents, only a few people can fully understand the system, reducing the development difficulty to a certain extent.

  • The three-tier architecture can better support the distributed computing environment. Applications on the logic layer can run on multiple computers, making full use of the computing functions of the network. Distributed Computing has a huge potential, far more effective than upgrading the CPU. The Americans used fractional computing to decrypt the password, which is said to be never cracked in just a few months.

  • The biggest advantage of a three-tier architecture is its security. Users can only access the data layer through the logic layer, reducing entry points and blocking many dangerous system functions.

4. Types of L3 Architecture

Currently, most team developers use hierarchical development architecture design during project development. The most common is layer-3 architecture, the purpose is to make each layer only affected by its adjacent layers, but this restriction is often violated when multi-layer development is used, which is harmful to system development. The three-tier architecture can be divided into three driving modes: The data layer driver mode, the presentation layer driver mode, and the isolation driver mode. The development of the isolation driver mode is the most important. The following compares the three modes to introduce the importance of the isolation driver mode.

 

Data layer driver mode

The so-called data-layer driving mode is to first design the data layer, and the presentation layer is centered around the data layer. Once the data layer and the presentation layer are completed, the business layer is centered around the data layer. Because the presentation layer is centered around the data layer, this will make the constraints in the presentation layer inaccurate, and limit the changes at the business layer. Due to restrictions on the business layer, some simple changes can be achieved through SQL queries and stored procedures.

This mode is very common. It is similar to traditional Client Server development and is designed around existing databases. Because the presentation layer is designed around the data layer, it often imitates the actual structure of the data layer intuitively.

 

There is often an additional feedback loop between the presentation layer and data. When the design presentation layer is not easy to implement, the data layer is often modified to form this feedback loop. The developer requests to modify the database to facilitate the development of the presentation layer, but it is harmful to the design of the data layer. This change is artificial without considering other requirements. Such modifications often violate at least the special rules that damage data, leading to unnecessary data redundancy and non-standardization of data.

Statement layer driver mode

The driver mode of the presentation layer is centered on the presentation layer. The completion of the business layer is generally achieved through simple SQL queries and few changes or isolation. Because the database is designed for the convenience of the presentation layer, rather than the data layer design, the database design is usually very low in performance. The presentation layer driver mode design diagram 1.6 is shown.

 

Isolation driver mode

Designed in an isolated drive mode, the presentation layer and data layer are independently developed, often parallel development. These two layers have no mutual interference during design, so there will be no human constraints or harmful design elements. After the two layers are designed, design the business layer. The responsibility of the business layer is to complete all the conversions without changing the Requirements of the data layer and the presentation layer. Presentation layer driver mode design.

 

Because the presentation layer and data layer are completely independent, when the business layer needs to change, the presentation layer and data layer can make corresponding changes without affecting the other party. Changing two physically non-adjacent layers does not directly affect or conflict with other layers. This allows the adjustment of the data layer structure or the change of the presentation layer based on the user's needs, without making major adjustments or modifications to the system. Table 1.1 compares the three driving modes.

Comparison of table drive modes

Data layer driver mode

Statement layer driver mode

Isolation driver mode

Database

(1) Easy to design

(2) Negative Impact

(3) It is difficult to change the data layer because it is closely bound to the presentation layer.

(1) Poor Database Design

(2) Serious nonstandard design

(3) other systems are not easy to use

(4) It is difficult to change the data layer because it is closely bound to the presentation layer.

(1) Optimization Design

(2) design the database in a centralized manner. The presentation layer has little impact on the database.

Business Requirements

Often unable to adapt to changes in business needs

Often adapt to changes in business needs

Adapt to demand changes

User Interface

Is around the data layer rather than around the user, not easy to modify

Suitable for user interface Extension

Suitable for user interface Extension

Scalability

Usually expandable, but the user interface usually requires a lot of rewriting to meet the structure of the database. At the same time, the database may need to store redundant fields.

It is difficult to expand the integrity. It is often achieved only through the "cut, paste" function.

Easy to expand

To sum up, it is easy to see the advantages of the isolation driver mode. The design of the isolation driver mode can greatly improve the scalability of the program. The application in section 1.3.2 adopts the three-layer architecture isolation driver mode.

 

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.