Role of each layer
1: Data access layer: mainly refers to the operation layer for raw data (in the form of storing data such as databases or text files), rather than raw data, that is, it refers to data operations, instead of databases, it provides data services for the business logic layer or presentation layer.
2: business logic layer: This layer is mainly used to address specific problems. It can also be understood as a pair of operations on the data layer. If the data layer is a building block, the logical layer is the construction of these blocks.
3: Presentation Layer: It mainly indicates the Web mode or winform mode. The Web mode can also be represented as Aspx. If the logic layer is quite powerful and complete, the logic layer provides complete services regardless of how the presentation layer is defined and changed.
Specific differentiation methods
1: Data access layer: it mainly depends on whether your data layer contains logic processing. In fact, its functions mainly perform operations on data files. You do not have to worry about other operations.
2: business logic layer: mainly responsible for operations on the data layer. That is to say, some data layer operations are combined.
3: Presentation Layer: mainly accept user requests and return data to provide applications for clientsProgram.
Layer-3 structure explanation
The layer-3 architecture adds an intermediate layer between the client and the database, also known as the component layer. The layer-3 system mentioned here does not refer to the layer-3 physical architecture, instead of simply placing three machines as the layer-3 architecture, or not just B/S applications as the layer-3 architecture, layer 3 refers to the logic layer 3, even if these three layers are placed on one machine. Applications in the layer-3 system put business rules, data access, and legality verification into the middle layer for processing. Normally, 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.
Developers can place the business logic of an application on the application server in the middle layer and separate the business logic of the application from the user interface. Provides a simple interface while ensuring the client functions. This means that if you need to modify the applicationCode, You only need to modify the Middle-layer application server, instead of modifying thousands of client applications. This allows developers to focus on the analysis, design, and development of the core business logic of the application system, simplifying the development, update, and upgrade of the application system.
So why should we apply the "intermediate business layer? For example:
Assume that there is a piece of login code, you can process the web program in this way. The appearance layer is responsible for receiving the data on the front-end page, and then passing it to the middle layer. The middle layer processes the data, such as formatting, anti-SQL injection and so on. Such data is then transmitted to the data access layer and then operated with the database, such as matching the database user name and password and other code.
The "intermediate business layer" has many functions, such as verifying user input data and caching data read from the database ...... However, the actual purpose of the "intermediate business layer" is to combine the basic storage logic of the "data access layer" to form a business rule. For example, "a shopping website has such a rule: the system automatically registers users who shop for the first time on the website ". Such business logic is most suitable in the middle layer:
In the "data access layer", it is best not to see any "business logic "! That is to say, to ensure the atomicity of function functions in the "data access layer! That is, the minimum and no score is allowed. The "data access layer" only stores or reads data.
The perfect three-tier structure requires that you modify the presentation layer instead of the logic layer, instead of the data layer. Otherwise, it is hard to say whether your application has a multi-layer structure, or whether there is a problem with the Division and organization of the layer structure. Different applications have different understandings. This is just a conceptual question.
Understanding the three-tier structure in ASP. NET-why should we divide it into three layers?
We use a three-tier structure to make the project structure clearer and the division of labor clearer, which is conducive to later maintenance and upgrade. It may not improve the performance, because when the subprogram module is not executed, the main program module can only be in the waiting state. This shows that dividing an application into layers will cause some loss in its execution speed. However, from the perspective of team development efficiency, we can feel a big difference.
It should be noted that the layer-3 structure is neither a. Net patent nor a technology dedicated to databases. It is a more universal architecture design concept.
I personally feel that this architecture should pay attention to the relationship between tables in the database design and try to satisfy the relationship between the master and sub-tables. Users must have certain functional limitations. do not exercise caution when deleting sub-tables, in this case, the foreign keys of the primary table that are logically present in the data of the primary table and the sub-table do not have the corresponding values in the sub-table.
The following table query methods are used:
First, query the master table and call the DL corresponding to the master table. Query each sub-table based on the records of the master table. A large query set is formed after the query result of the Self-table is added to the master table.
Operations on tables (add, delete, and modify ):
In this case, only the primary table is operated and the operation method in the DL corresponding to the primary table is called.
The RL layer is the logical judgment layer, mainly used to perform logical judgment on the data uploaded to the page. Above the RL layer is the UI
How to build a three-tier architecture solution
Create a blank solution. Then:
"Add"-"New Project"-"Other Projects"-"Enterprise template project"-"C # generate blocks"-"Data Access" (data layer, hereinafter referred to as layer D)
"Add"-"New Project"-"Other Projects"-"Enterprise template project"-"C # generate blocks"-"Business Rules" (business layer, hereinafter referred to as layer C)
"Add"-"New Project"-"Other Projects"-"Enterprise template project"-"C # generate blocks"-"Web User Interface" (interface layer, (U layer)
Right-click solution> Project dependency, and set u to depend on D, C, and D.
Add references D and C to U, and add references d to C.
so far, a three-tier shelf has been established. What I said above is very specific and "stupid". People who know me think I am nonsense. In fact, during this time, I strongly felt that many people actually did not understand this simple process. Although there is no objection to creating two "Empty Projects" and one "asp net Web Application Project", it can also be used as a three-layer framework, many people think that these "enterprise-level template Projects" are actually empty projects, which is a misunderstanding. Yes, you can see from the solution resource manager that there is nothing in the enterprise-level template project. But you can open the project file in notepad and see the difference ?? You can't see some things behind the scenes, but the system is ready. That is to say, if you "using system data sqlclineit" in a class in the C layer or use a sqlconnection object, no errors will occur during compilation, however, some "policy warnings" will be generated in the "task list" to warn you not to put things that should be placed on layer d in the C layer (although the program is correct, but the readability and maintainability are discounted.) This function cannot be provided to empty projects.