If there is one architectural design approach in the server-side technology world, it must be the “layered architectural design” approach.
preface
“Layering” is a way of thinking, a way of solving complex problems, and an architecture.
“Layered architecture” refers to the separation of the components of a system into different layers, with the components in each layer remaining cohesive and at roughly the same level of abstraction; Each layer should be loosely coupled to the layers below it. “Hierarchical architecture design” is a systematic approach to software architecture design using hierarchical thinking.
The reason why layered design is so widely applicable is that it contains two advantages that correspond to the six words of architectural design.
Six words of architecture design: High cohesion and low coupling
Advantages of layered design:
- The clustering mode with high cohesion is defined by Layer Layer
- Low coupling communication is defined with the upper layer only calling the lower layer
The body of the
Software developers are professionals, and professionals can be defined and described in professional terms. Architectural styles and patterns A professional way of describing architectural design. The styles and patterns of “layered architectural design” are described below.
- Architectural Style – Layered architecture, constraints (layered, upper dependent on lower, lower dependent on upper)
- Architecture pattern – Three-tier system architecture, N-layer system architecture
Three-tier system architecture
The three-tier architecture is a design approach that comes out of the mouth of server-side developers. Hierarchical architecture has a general rule of “technology crosscutting service vertical cutting”. The three layers of a three-tier system architecture mainly refer to the three cross-cutting technology layers, which are mainly used for high cohesion and low coupling of technical components. The main features of the third floor are as follows.
level | features |
---|---|
The presentation layer | Also known as the UI layer, the presentation layer supports user access and provides apis for external users to access, mainly defining the input and output of user behavior. |
The business layer | Also known as the service logic layer, it mainly processes the service logic of user scenarios, including checking the validity of input data and processing the service logic. |
Persistence layer | Also known as the database layer, support business data persistent storage, the general Web system refers to the relational database. |
What is the relationship between three-tier system architecture and MVC?
Some students confused the three-tier system architecture with MVC. In fact, the two are design methods in different dimensions. MVC (Model-View-controller) is generally regarded as a design method of “presentation layer”.
N-layer system architecture
Since there are three layers of system architecture, there must be more layers of system architecture design, for example, in the design level can also take the database as a single layer, forming a four-layer architecture design.
Four-tier architecture design:
Similarly, in addition to four layers, there can also be five/six layers and other design methods.
Hexagonal system architecture
Similarly, continue to expand the design method of layered architecture, in addition to upper and lower layers can also be internal and external layers, hexagonal architecture design method is a design method of internal and external layers.
The purpose of hierarchical architecture design is to reduce coupling and improve functional reuse, but business logic is inevitably separated in different levels, which leads to the decentralization of core business logic, which leads to the difficulty of continuous iteration and the failure to independently test and verify business logic. In addition, with the popularity of microservice architecture, Software architecture design also develops from one-dimensional design to multidimensional design, and the original hierarchical architecture design method can not support this change well.
Hexagonal architecture design:
Hexagon architecture design from inside to outside into the business core layer, support layer, adapter layer, the design method of the business, to distinguish internal and external technology, effectively prevent leakage the business logic to the problem of multi-layered, and through the adapter design method can replace the tripartite framework services, the purpose of an independent business logic validation.
case
One of the best known results of layered design is TCP/IP’s seven-layer network protocol and five-layer model.
conclusion
There is a design description method of “north, South, east, west”, which is also a layered architecture design method. Compared with southeast, northwest, I prefer the layered architecture design. A “layered” summarizes all the characteristics of the architecture, but also reflects the essence of solving complex problems: decomposition and segmentation.
If using an analogy, design is more like cutting a cake. In addition to vertical cutting, it can also be cut horizontally, diagonally, cut together with plates, cut together with tables, and combined cutting, etc. Each cutting method can be like “hexagonal architecture”. A new architectural design method can be named.
The architectural design is not accomplished overnight. In general, the architectural style is determined and the team consensus is reached, and the design is gradually evolved.
reference
- Architectural styles and patterns
- Understand architecture design
- The C4 model