The original URL will be updated continuously :Technical Blog for the process "Layering of enterprise application architectures-Summary" it.zuocheng.net
common layered schema patternsThree-tier architecture 3-tier architecture
The hierarchical structure recommended by Microsoft. NET system is widely used in ASP coding system, and it is also widely used in other languages.
Presentation layer, Presentation layer (PL)
Mainly responsible for data input interface and output. Input refers to the data request interface of the Web, client, or API provided by the outside world, and the output is the data output of the Web interface, client output, and API.
page templates, external API data formatting, request acceptance, output push, commander operations are all at this level.
Business logic layer, bisiness logic layer (BLL)
Mainly responsible for the intermediate process from raw data to result data. The most critical and important layer in the system. Also known as the domain layer, the logical relationships and functional implementation algorithms for all objects in the domain are in this layer.
Business logic, services, etc. are at this level.
Data access Layer (DAL)
The primary is the operational layer (CRUD operations) of the raw data, which provides data services for the business logic layer or presentation layer. Data sources include databases, files, networked storage systems, other system-open APIs, program run contexts, and so on.
The ORM, Active Record, Dao class, or library in many frameworks are at this level.
Three-tier Architecture summary
The three-tier architecture can satisfy most business scenarios and achieve high cohesion and low coupling. The logical decoupling or isolation between different levels becomes weakly dependent, with the logical cohesion of each layer. From the level point of view, the system has a good scalability.
The deficiencies of the three-tier architecture are:
- A system with high complexity of business logic, the business logic layer will become bloated, in order to solve this problem, four-tier architecture/multilayer architecture was proposed.
- Do not focus on the implementation of the presentation layer.
Four-tier architecture 4-tier architecture
The four-tier architecture is very similar to the three-tier architecture, which is divided into presentation layer, service layer, business logic layer and data access layer. In addition to the service layer, the three tiers of the other three-tier and three-tier architectures are almost identical, and the service layer is a subdivision of the business logic layer in the three-tier architecture to address the often bloated problems of the business logic layer.
The four-tier architecture is the Java EE recommended layered architecture, especially the Java spring+struct+hibernate (SSH) combination framework that makes the DAO layer, service layer, clear definition and specification. Because the SSH framework is widely used, other frameworks, including the frameworks of other languages (such as PHP), also draw on SSH, so you can see the abstract definition of DAO classes and service classes in these frameworks.
services layer, Service layers
In the three-tier architecture, the upper logic of the business logic layer is separated to form the service layer. The service layer is often the logical presentation layer, which provides the logical appearance to the upper layer (the presentation tier). Transaction control, security checks, transaction scripts, etc. can be placed into the business layer (refer to Martin Fowler's "architecture Model for enterprise Applications")
Four-tier Architecture summary
A four-tier architecture is the development or evolution of a three-tier architecture. The advent of the service layer has made the business logic layer of the three-tier architecture no longer bloated.
There is a shortage of four-tier architecture and three-tier architecture, that is, the implementation of the front end is not emphasized. Better solutions are needed when faced with the need for a personalized interface, complex user interactions, and a dependency between pages.
MVC pattern
The MVC pattern consists of three parts, the Model View controller (models-view-controller).
The most prominent advantage of MVC compared to a three-tier or four-tier architecture is the flexibility of front-end control. If two parts of MVC, view and controller are stripped out, is actually a design pattern called front-end controller mode.
The drawbacks of MVC are obvious, putting the logic outside the front end in the model, and as the business grows, the model becomes harder to maintain.
MVC is not intended to be called a layered architecture, but is better suited to a design pattern called a composite. Some people also classify the MVC pattern as a front-end schema.
Why is the MVC pattern widely adopted? This is what the author thinks:
- The MVC pattern is best suited to news portals, display sites, and the business logic of such sites is often simpler.
- The MVC pattern is best suited for start-up, because the initial logic of the project is simple, the use of MVC mode products can be quickly formed, can be put into the market early test (most likely to be eliminated), thus reducing the cost of testing. (If the product has potential, the system will inevitably face the stress of refactoring as the business grows and becomes more complex in the middle and late stages.) )
- The MVC pattern is best suited to the implementation of a product prototype (focus on the front end).
Other layered schemas
In addition to the three/four layer architecture, the MVC pattern, there are many architectural patterns, but these are mostly similar to the three/four layer architecture, the MVC pattern, or extend and transform on top of them. such as MVVM (Model-view-viewmodel), MVP, DDD architecture mode, and so on.
The idea or purpose of layering.
- High cohesion
- Low coupling
- Enhanced scalability of the system
- Enhanced maintainability of the system
Benefits of layering
- A developer can focus on only one of the layers in the entire structure;
- can easily replace the implementation of the original level with the new implementation;
- Can reduce the dependence between layer and layer;
- conducive to standardization;
- Facilitates the reuse of all layers of logic.
- A more explicit structure
- Significantly reduced maintenance costs and maintenance time during post-maintenance
Disadvantages of layering
The disadvantages of layering are negligible compared to the advantages of layering.
- Using hierarchies increases the amount of code, but clear architecture and code reuse reduces development costs and maintenance costs.
- Layering, while logically increasing the number of calls to the code, increasing the number of logical branches, reducing performance, but this part of the performance of the system and the real performance bottleneck (storage io, network IO, high-level language) compared to the small.
- Hierarchies sometimes result in cascading modifications, but this can be resolved through design patterns such as interface-oriented design or the use of a mediator pattern, façade mode, adapter mode, and so on.
How to design a tiered architecture
- Software development is to follow the process from simple to complex, software architecture is also an iterative process, is a gradual, continuous improvement process. In short, continue to refactor.
- Use the Java EE (J2ME) hierarchical specification for reference or directly, and use the naming of the DAO, service, and other classes.
- The interaction between layer and layer, to follow the principle of interface-oriented design, the use of design patterns.
- The choice of layering is to balance the costs and risks and maximize the benefits.
- Business logic is not confined to a four-tier or three-tier architecture, and can be subdivided into layers based on domain business features.
Layering of enterprise application architectures-Summary