User interface presentation layer (USL), business logic layer (BLL) and data access layer (DAL).
BLL separates USL from DAL, and adds the functions of each layer of business rule 1: data access layer: it is mainly the operation layer of original data (stored in the form of database or text file), not the original data, that is, it is the operation of data, not the database, and specifically provides data services for business logic layer or presentation layer.
2. Business logic layer: mainly for the operation of specific problems, which can also be understood as the operation of data layer and the logical processing of data services. If the data layer is a building block, then the logical layer is the construction of these building blocks.
3. Presentation layer: it mainly represents WEB mode, which can also be represented as WINFORM mode, and WEB mode can also be represented as: aspx. If the logic layer is quite powerful and perfect, then no matter how the presentation layer is defined and changed, the logic layer can provide services perfectly. Specific distinguishing method
1: data access layer: mainly depends on whether your data layer contains logical processing. In fact, its function is mainly to complete various operations on data files. Regardless of other operations.
2. Business logic layer: mainly responsible for the operation of data layer. In other words, some data layer operations are merged.
3. Presentation layer: it is mainly used for user's request acceptance and data return, and provides access to application programs for clients. Three-layer structure interpretation
The so-called three-tier architecture adds an intermediate 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. Three-tier application puts business rules, data access, legitimacy verification and other work in the middle layer for processing. 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.
Developers can put the business logic of the application on the middle-tier application server and separate the business logic of the application from the user interface. On the premise of ensuring the function of the client, it provides a simple interface for users. This means that if you need to modify the application code, you only need to modify the middle-tier application server instead of modifying thousands of client applications. It enables developers to concentrate on analyzing, designing and developing the core business logic of the application system, which simplifies the development, updating and upgrading of the application system. So why apply the "intermediate business layer"? Give a few examples:
Suppose there is a login code, we can handle the Web program like this. The appearance layer is responsible for receiving the data of the foreground page and then passing it to the middle layer, which processes the data, such as formatting, preventing 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 user name and password of the database and so on.
The "intermediate business layer" has many uses, such as verifying the data input by users and caching the data read from the database ... but the actual purpose of the "intermediate business layer" is to combine the most basic storage logic of the "data access layer" to form a business rule. For example, "a shopping website has a rule that users who shop on the website for the first time will be automatically registered by the system." This kind of business logic is best placed in the middle layer: in the "data access layer", it is best not to have any "business logic"! In other words, we must ensure the atomicity of the functions in the data access layer! That is minimalism and inseparability. The "data access layer" is only responsible for storing or reading data.
ASP.NET's Three-layer Structure Description
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 has a multi-tier structure or whether there is a problem with the division and organization of the tier structure. Different applications have different understandings, which is only a conceptual problem. Understand the three-tier structure in ASP. NET- why should it be divided into three layers?
We adopt the three-tier structure mainly to make the project structure clearer and the division of labor clearer, which is conducive to the later maintenance and upgrading. Performance may not be improved because the main program module can only be in a waiting state when the subroutine module is not executed. It can be seen that layering the application will bring some losses to its execution speed. But from the perspective of team development efficiency, we can feel completely different effects.
It should be noted that the three-layer structure is not a patent. NET, nor is it a technology specially used for databases. It is a more general architectural design concept.
This architecture should pay attention to the relationship between tables in database design and try to satisfy the master-slave relationship. There should be some restrictions on the user's function, which should not be reflected in the caution of deleting the sub-table, so as to avoid logical errors in the data of the main table and the sub-table, and the foreign key of the main table has no corresponding value in the sub-table. The comprehensive query method of this table is:
First, query the main table and call the DL corresponding to the main table. Then query each sub-table according to the record of the main table. After the query results in the table are added to the main table, a large query set is formed.
For table operations (add, delete and modify):
At this time, only the main table is operated, and the operation method in DL corresponding to the main table is called.
RL layer is a logical judgment layer, which mainly judges the data uploaded by the page. Above the RL layer is how the UI builds a three-tier architecture solution.
Create a new blank solution. Then:
Add-New Project-Other Projects-Enterprise Template Project -C # Building Block-Data Access (data layer, hereinafter referred to as D layer)
Add-New Project-Other Projects-Enterprise Template Project -C # Building Block-Business Rules (business layer, hereinafter referred to as C layer)
Add-New Project-Other Projects-Enterprise Template Project -C # Building Block -Web User Interface (interface layer, hereinafter referred to as U layer).
Right-click Solution-Project Dependencies, set U as Dependency D, and set C and C as Dependencies D.
Add references d and c to u and reference d to C.
So far, a three-story shelf has been set up. What I said above is very specific and "stupid". Everyone who knows thinks I'm talking nonsense. In fact, I have a strong feeling that many people actually don't understand this simple process at all. Although there is no objection to building two "empty projects" and 1 "Asp net Web application projects" which can also be used as a three-tier framework, quite a few people think that these "enterprise-level template projects" are actually empty projects, which is a misunderstanding. Yes, the enterprise template project is nothing in Solution Explorer, but you can open the project file with Notepad. See the difference? Some things have passed, but the system is ready. That is to say, if you "use the system data sqlclinic" in a class in the C layer, or use the SqlConnection object, there will be no mistakes at compile time, but some "policy warnings" will be generated in the "task list" to warn you not to put things that should be placed in the D layer in the C layer (although it is true in terms of programs, the readability and maintainability are compromised). This function cannot be realized by an empty project. In the new Trace Word 3, "Enterprise Template Project" is applied. Put the original LWordTask.cs into a single project called AccessTask. A new project named InterService is created in the solution, which contains a program file LWordService.cs, which is an "intermediate business layer" program. In order not to be named repeatedly, the website of Trace Word 3 was placed in the WebUI project. A more complete code can be found in the code package /trace word 3 directory-the combination of object and reality.
We know that building a bridge requires bricks, so we should prepare bricks before building a bridge, but for the sake of order, consistency and simplicity. Let's build the bridge first, and the bricks need to be produced in the process of construction, so that there will be no more "things that the bridge doesn't need". Note that in actual operation, bricks should be prepared first.
U-layer is actually a bridge, C-layer is a brick, and D-layer is a raw material (stone, sand). This also explains why U layer should refer to and rely on D layer (instead of U-to-C and C-to-D layer), because the bridge needs not only bricks, but also stones and sand. Disadvantages of "three-tier structure" Some netizens have asked me some questions after reading the previous work of this article, which reminds me of the shortcomings that the article has not mentioned the "three-tier structure" so far. The word "three-tier structure" seems to have always been popular, and the reason may be that this development model is widely used. However, the "three-layer structure" is not a panacea for Bailing, and it also has some shortcomings. Let's talk about its shortcomings first ... a very obvious shortcoming of the "three-tier structure" development model is that the execution speed is not fast enough. Of course, this "execution speed" is relative to non-hierarchical applications. From the timing chart given in this paper, this shortcoming is also obvious. TraceLWord 1 and TraceLWord2 are not hierarchical, and the class provided by ADO.NET is directly called to obtain data. However, the tracking word 6 must be called many times to get the data. When the subprogram module program does not return, the main program module can only be in a waiting state. Therefore, in terms of execution speed, the higher the message board version, the lower the ranking. The "three-tier structure" development model is not suitable for systems that require too strict execution speed, such as online booking, online stock trading, etc ... It is more suitable for systems whose business rules are easy to change. The "three-layer structure" development model is difficult to get started and understand and learn. This is for beginners in programming. Software developed in this mode usually has more code. This often makes beginners drown in the vast amount of code. It is understandable to feel fear and disgust at this ... in fact, no matter what development mode or method, there are advantages and disadvantages. There will be no "one size fits all" solution to any problem. So the word "three-layer structure" is no exception! Whether to adopt this mode for system development can only be done after comparison and weighing. Avoid abuse!