My understanding of the three-tier architecture

Source: Internet
Author: User
Navigation in this article: (typographical layout is good,)
  • What is a three-tier architecture?

    • Concept
  • Introduction to Layer 3 and its responsibilities
  • Relationship between layers and rules
    • Link
    • Rules
  • Advantages and disadvantages of L3 Architecture
    • Advantages
    • Disadvantages
  • Summary
What is a three-tier architecture? Concept

  • A layer-3 architecture generally divides the entire business application into the presentation layer (UI), business logic layer (BLL), and data access layer (DAL ). The purpose of hierarchy differentiation is the idea of "high cohesion and low coupling.
  • Tip:
    • A three-tier architecture is not just a three-tier architecture, but n-tier architecture.
    • The three-tier architecture does not simply divide the code into three layers.
    • The layer-3 architecture is not to deploy the program in three different places, it is called the layer-3 architecture.
Introduction to Layer 3 and its responsibilities

  • Presentation layer (UI): mainly responsible for obtaining data and displaying data for users. For example, the form in the application and the web in the B/S system.

    • The U layer shall not share the responsibilities of the BLL layer, and should not include any logic except some simple judgment logic.
  • Logic layer (BLL): it is important to be responsible for logical processing. All logic should be concentrated at this layer, and transaction processing should also be enabled at the logic layer.

    • The logic layer is the core of the entire system. This layer can be divided into many sub-layers. For example, The bll layer is divided into two layers: Business Flow and business function. business function is responsible for completing some small business functions, busines flow is responsible for combining small business logic into large business flows.
    • Transaction processing is enabled at The bll layer. Because layer B is responsible for processing the business logic, it is most reasonable to start the transaction at this layer.
    • The design of the logic layer directly affects the scalability, maintainability, and reusability of the system. Therefore, the logical layer uses the most design patterns.
  • Data access layer (DAL): it is mainly responsible for direct access to the database and shields database differences from the top layer.
    • The data access layer is generally divided into two layers. It mainly abstracts the common operations in the Dal layer into a class, for example, sqldbhelper.
Relationship between layers and rules

  • Below is a simple three-layer UML package diagram I drew.
Link
  • No cross-layer invocation is allowed between all levels of the system and its sub-layers.
  • Entity transmits data between layers.
  • The call between layers is unidirectional, from top to bottom, that is, u calls layer B, and layer B calls layer D.
Rules
  • Parameters are transmitted between layers in the form of entity classes. Do not transmit parameters in the form of variables. Instead, they are transmitted in the form of variables that do not conform to the idea of object-oriented programming.
  • Data bound to the list at the U layer is returned in the form of dataset or datatable. We recommend that you return data in the form of entity classes or object sets except for the number of times. Because dataset has many disadvantages. For more information, see my blog (weak and strong datasets)
  • Each database table has a DB entity class corresponding to it.
  • Each database entity corresponds to a Dal.
  • Dal implements the same interface to avoid database differences. After the abstract factory mode + reflection + configuration file is adopted, even if the database is changed, you only need to rewrite the configuration file.
  • SQL statements should not appear on any layer except layer D.
  • The design should minimize data transmission at different layers.
Advantages and disadvantages of L3 Architecture

Advantages

  1. Reduces maintenance costs and facilitates management.

    • The hierarchical architecture of the system allows you to directly replace and update components at different layers of the system, and directly replace DLL files to complete system updates. In this way, just like changing a car's tires, you don't need to send the car to the manufacturer for installation. You just need to replace it directly. Because components are independent of each other.
    • The logic is mainly at Layer B, so that the U layer, that is, the client, does not assume too many responsibilities. Even if the business logic is updated, the client does not need to be modified and no redeployment is required.
  2. It has inherent advantages for ever-changing systems.
    • The three-tier design is designed according to the object-oriented thinking. The program is highly scalable and has great advantages for systems with changing requirements. If there is no hierarchy, the program must be rewritten and compiled as long as a small change is made.
  3. SHIELD database differences.
    • A system designed based on a three-tier architecture has no pressure on Database changes. A very important role of layer D in Layer 3 is to avoid database differences. Abstract Factory mode + reflection + configuration file makes it easier to replace the database. Even if the database is not taken into account during design, it is to re-write the dal and dbhelper, and the system itself does not need to be re-compiled.
  4. Suitable for large-scale projects and cooperative development.
    • The three-tier architecture makes cooperative development possible. Because each layer is independent of each other, a group only needs to be responsible for a small part. Structured programming methods are insufficient for large projects, because structured design will surely complicate the program.
  5. Security.
    • The three-tier architecture makes the interface, business logic, and data access independent from each other. Data can be encrypted and transmitted between layers. The business logic layer and database access layer can be deployed on different servers, and even the business logic can be deployed on different servers respectively. In this way, the server firewall makes the system more secure.
Disadvantages
  1. Execution speed.

    • Because there are more layers, it is certainly slower to transmit data between layers than to directly access data. It may not be suitable for systems with high speed requirements.
  2. Large amount of code.
    • The first time I use a three-tier architecture, I may feel that the amount of Code has increased significantly. However, I think it is worthwhile to write more code to facilitate maintainability.
    • The three-tier architecture modules are independent of each other, enhancing the reusability of modules. For example, after a company has done similar projects, it will cost less to face the same project. This is the advantage of reusability.
Summary

  1. The hierarchy is not dead. No division can adapt to all systems. To learn Layer 3, we need to understand its essence and its purpose. It is not so much an architecture as an idea.
  2. The three-tier architecture is a kind of architecture summarized by our predecessors to achieve program scalability, reusability, readability, maintainability, and convenient cooperative development. In fact, the three-tier architecture is the inevitable result of object-oriented development. In order to achieve the above features, layering is inevitable.
  3. There is no way to determine the hierarchy, but as long as there is a high cohesion and low coupling Object-oriented Thinking to split, as long as it can meet the requirements of encapsulation, reuse, expansion, placement and other aspects.
  4. The Learning hierarchy is the same as the learning design pattern. At the beginning, we always start from imitation, and we will be especially concerned about various rules and regulations. However, this is a process that has to be experienced. The learning hierarchy is not to learn the hierarchy itself, just as the learning design model is not the learning model itself, it is important to understand the charm of object-oriented design in this process and to understand the accumulation of previous ideas. Whether layered or design patterns are giants, what we need to do is to stand on their shoulders and then become giants, surpassing giants.

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.