Generally speaking, the three-tier architecture actually divides the whole business application into presentation layer, business logic layer and data access layer.
The three-tier architecture adds a "middle layer" between the client and the database, also known as the component layer. The three-tier system mentioned here does not mean physical three-tier, or simply putting three machines or a three-tier architecture, nor is it only B/S applications that are three-tier architecture, but three-tier refers to logical three-tier, even if the three-tier are put on one machine.
Ordinary three layers: data access layer DAL: the part used to realize interaction and access with the database, obtain data from the database or save data in the database. Business logic layer (BLL): The business logic layer is a connecting link between the preceding and the following, and it is used to logically process the data interacting up and down to achieve business goals. Presentation layer UI: it mainly realizes the interaction with users, receives user requests or returns the display of data results requested by users, while the specific data processing is handed over to business logic layer and data access layer. Business entity model: used to encapsulate the data structure of entity classes, and generally used to map data tables or views of databases to describe objective objects in business. Model separation is to better decouple, better play the role of layering, better reuse and expansion, and enhance flexibility. General: A general auxiliary tool class.
Engineering mode: factory method mode, also known as static factory method mode, belongs to the creation mode of classes, and usually returns different instances of classes according to a condition (parameter).
Factory Role (Creator)
Is the core of the factory method pattern, responsible for creating instances of all concrete product classes. Factory classes can be directly called by the outside world to create the required product objects.
Abstract product (product)
Is the parent class of all specific product roles, and it is responsible for describing the common interfaces owned by all instances.
Product-specific roles (specific products)
Inherited from abstract product roles, there are usually multiple roles, which is the creation goal of factory method pattern. The factory class returns the specific product of the role.
Usually, the client does not directly interact with the database, but establishes a connection with the middle layer through COM/DCOM communication, and then exchanges with the database through the middle layer.
The requirements of a perfect three-tier structure are: modify the presentation layer without modifying the logic layer, and modify the logic layer without modifying the data layer. Otherwise, it is hard to say whether your application is a multi-layer structure or whether there is a problem with the division and organization of the layer structure. Different applications have different understandings, which is a conceptual problem.
Conceptually, the models in MVC system can be divided into two categories ―― the internal state of the system and the actions to change the state of the system. The model is where all business logic code fragments are located. This paper provides business entity objects and business processing objects for this model: all business processing objects are subclasses derived from the ProcessBase class. The business processing object encapsulates specific processing logic, calls the business logic model, and submits the response to the appropriate view component to generate the response. Business entity objects can describe client form data by defining attributes. All business entity objects are subclasses derived from EntityBase, and business processing objects can read and write it directly without data interaction with request and response objects. Business entity objects support the interaction between views and models. Realize the separation of "what to do" (business processing) and "how to do it" (business entity). This can realize the reuse of business logic. Because the specific business of each application is different, specific code examples are not listed here.
MVC (Model-View-Controller) is a design pattern, which can be used to distinguish domain objects from UI presentation layer objects. Also at the architectural level, the same place is that they all have a presentation layer, but their difference lies in the other two layers. The concept of controller is not defined in the three-tier architecture. This is the most different place for me. Moreover, MVC does not regard the logical access of business as two layers, which is the main difference between adopting a three-layer architecture or MVC building program. Of course. The model is also mentioned in the three layers, but the concept of the model in the three-layer architecture is different from that in MVC. The typical model layer in the "three layers" consists of entity classes, while in MVC, it consists of business logic and access data.
Written with MVC framework in ASP NET, it has excellent expansibility. It can easily realize the following functions: ① to realize multi-view of a model; (2) adopting multiple controllers; ③ When the model changes, all views will be automatically refreshed; ④ All controllers will work independently of each other. This is the advantage of MVC architecture. You can easily add many program functions by slightly modifying the previous program or adding new classes. Many classes developed in the past can be reused, but the program structure does not need to be changed at all, and the classes are independent of each other, which facilitates group development and improves development efficiency. How to realize a model, two views and a controller program is discussed below. The model class and view class don't need to be modified at all, just like the last one. This is the advantage of object-oriented programming. For the class in the controller, just add another view and associate it with the model. The schematic diagram between the view, controller and model in this mode is shown in Figure 2. Other forms of MVC can also be implemented, such as one model, two views and two controllers. As can be seen from the above, the application realized through MVC architecture has excellent scalability and is the future direction of object-oriented programming in ASP NET.
The disadvantages of MVC are: (1) increases the complexity of system structure and implementation. For a simple interface, strictly following MVC and separating model, view and controller will increase the complexity of the structure, and may produce too many updating operations and reduce the running efficiency. (2) The connection between the view and the controller is too tight. View and controller are separated from each other, but they are closely related. Without the controller, the application of views is very limited, and vice versa, which hinders their independent reuse. 3) Inefficient access of views to model data. Depending on the operation interface of the model, it may be necessary to call the view several times to get enough display data. Unnecessary frequent access to unchanged data can also damage operational performance. (4) At present, the general advanced interface tools or constructors do not support MVC architecture. It is very expensive to transform these tools to meet the needs of MVC and build separate components, which makes MVC difficult to use.
The three-tier architecture divides the code into three parts according to the function, and each part solves its own responsible process. The function of three-tier architecture is to control the structure of large-scale web programs and make them easy to manage and expand.
When designing UI, we don't need to care about logic and data, we just need to leave the corresponding location where the data is placed. When designing and modifying, we only need to solve the structure of HTML, and the code looks clean and tidy.
The UI directly throws the task of program logic to BLL, and BLL starts to build specific implementation details. The creation of BLL depends on business. For example, an article system, BLL _ articles, means that it is used to process articles. BLL _ article can provide a record set of article list for UI, which is displayed in the reserved position of UI. When the BLL particle needs to get data from the database, it throws the task to the DAL layer.
DAL layer is responsible for processing the database. It obtains parameters from BLL, organizes effective SQL, establishes database connection, executes SQL to update or obtain, and gives the returned data to BLL.
Every part of the business is concentrated in a UI-BLL-DAL chain, which can be seen at a glance from top to bottom. As for how to facilitate management and expansion, examples will be analyzed later.
Complex life forms must have complex survival rules. If you want to apply the three-tier architecture in your own project, you need to experience the application rules with snacks.
My understanding of the three-tier architecture is not deep enough, and these articles are a good inspiration. When reading, don't be limited to the laws I conceive, but practice them in specific applications and find out your own laws according to specific conditions. If you feel something, remember to write it down. This feeling is an opportunity for progress, but it is not necessarily the final result. If you have a feeling, you can apply it, find its advantages and disadvantages and continue to improve.
Three-tier architecture has greater advantages than double-tier or single-tier architecture. The three-tier structure is suitable for group development, everyone can have different division of labor, and cooperation can double the efficiency. When developing two-tier or single-tier applications, every developer should have a deep understanding of the system, which requires high ability. When developing three-tier applications, talents in various fields can be combined, and only a few people need to have a full understanding of the system, which reduces the difficulty of development to some extent.
The three-tier architecture belongs to the thin client mode, and the client only needs smaller hard disk, smaller memory and slower CPU to get good performance. In contrast, single-layer or fat customers demand too much face equipment.
Another advantage of three-tier architecture is that it can better support distributed computing environment. The application of the logic layer can run on multiple machines, making full use of the computing function of the network. Distributed computing has great potential and is far more effective than upgrading CPU.
The biggest advantage of three-tier architecture is security. The client can only access the data layer through the logical layer, which reduces the entry points and shields many dangerous system functions.
Shi Mingyuan replied