From MVC architecture to three-tier (3-Tier) architecture

1. The pain points of MVC

For scenarios where the business logic is not very complicated, MVC is still competent. However, with the rise of the front-end MVVM (Model-View-View-Model) development model, especially the popularity of front-end frameworks such as , the Vueuse of Reactserver-side MVCdesign patterns has become less and less, because server-side rendering is no longer required View.

In addition, MVCin fact, the layered design pattern is still coarse-grained:

  • ModelLayered code not only maintains data, but also encapsulates business logic . As business logic becomes more and more complex, the functional logic of this layer will become more and more bloated and difficult to maintain.
  • For team management, the responsibility boundaries of Controllerand are relatively blurred , and the requirements for developers to write good code will be relatively high.Model

Two, 3-Tier Architecture (three-tier architecture)

Although it is sometimes MVCcalled a three-tier architecture, the three-tier architecture has a specific term (3-Tier Architecture).

2.1 Presentation Layer — UI

User InterfaceLocated at the top of the three-tier structure, it is in direct contact with the user, mainly the WEB page in the B/S, and it can also be the API interface. The main function of the presentation layer is to realize the input and output of system data. During this process, the data can be transmitted to the BLL system for data processing without the need for logical judgment operations, and the processing results will be fed back to the presentation layer after processing. In other words, the presentation layer is to implement user interface/API interface functions, communicate and give feedback on user needs, and use BLL or Model for debugging to ensure user experience.

2.2 Business Logic Layer - BLL

Business Logic LayerIts function is to make logical judgments and execute operations on specific issues. After receiving user instructions from the presentation layer UI, it will connect to the data access layer DAL. The business logic layer is located in the middle of the presentation layer and the data layer in the three-layer architecture.

2.3 Data Access Layer — DAL

Data Access LayerIt is the main control system of the database, which realizes operations such as adding, deleting, modifying and checking data, and feeds back the operation results to the business logic layer BLL. In the actual operation process, the data access layer has no logical judgment ability. In order to achieve the rigor of code writing and improve the code reading level, general software developers will implement general data capabilities in this layer for encapsulation (for example, through ORM components) to ensure the data processing function of the data access layer DAL.

2.4 Model definition layer — Model

The model definition is also often Entityrepresented by entity objects, which are mainly used for mapping objects of database tables. In the actual development process of information system software, object instances should be established to express relational database tables in the form of object entities, which assists in the control and operation of various system functions in software development. Establish an entity class library, and then realize the parameter transmission of each structural layer, and improve the readability of the code. In essence, the entity class library mainly serves the presentation layer, business logic layer, and data access layer, and transmits data parameters between the three layers to strengthen the simplicity of data representation.

It should be noted that although the Model here and the Model in the MVC design pattern have the same name, the difference is huge, and the responsibilities are completely different.

Guess you like

Origin blog.csdn.net/weixin_45651194/article/details/129094753