Learning ASP. NET knows that its most classic architecture is a three-tier architecture, which is also the most widely used architecture. in the past, we all know the MVC Architecture as a three-tier architecture, which is widely used in html development. Currently, AJAX mainly uses this architecture. ASP. the third layer of NET is the index data access layer, the business logic layer and the presentation layer. It is also known that the data access layer is used to access data, and the business logic layer is used to process the business logic of some systems, the presentation layer presents the content to the user and interacts with the user. The benefit of dividing three layers is that each layer is independent. Modifying one layer does not affect the code of other layers, which greatly facilitates future maintenance and upgrade. Its biggest drawback is that the architecture and coding are complicated, and it does not help improve the performance, but may also reduce the execution efficiency.
Sometimes I really think it is quite troublesome to compile the "Three Layers", in ASP. in NET 2.0, you only need to drag two controls (AccessDataSource/SQLDatasource and GridView) to access data and display them. In a few minutes, a page is displayed and can be modified and deleted, paging, sorting, and other functions. It is much more troublesome to use a three-tier architecture. First, you must write the code at the data access layer, then write the code at the business logic layer (call the method at the data layer), and finally the presentation layer, that is, the design of the page and the code that calls the business logic layer to read data. (Note: The presentation layer will never access the content of the data layer, but only through the business layer. Here, the business layer serves as a bridge connecting them. Therefore, the business layer is the most important layer.) So why should we use three layers? A major problem with the layer-1 architecture mentioned above is that the front-end and back-end code are not well separated, which is not conducive to division of labor. Second, it is not conducive to future maintenance and upgrade. If it is a personal homepage or a few small systems completed by a person, it is quite helpful to use one layer. For some large systems, especially enterprise applications, three layers or even n layers are not required. Generally, three layers are enough. Dividing more layers only increases the difficulty of design and coding.
So how to layer it? How can we achieve layer-3 architecture principles? This is a frequently asked question by many beginners. I have read a lot of case books, but unfortunately many of them are either one-or two-tier architecture, with few three-tier architecture. Later, I studied petshop4.0 and some foreign data to find out how to arrange layers. I have summarized the following three layers:
1. The data layer does not contain any code, only databases, and related stored procedures.
In this mode, the data layer looks very simple. Only the databases you have created and some stored procedures are included (Note: stored procedures ). In fact, the creation of these stored procedures is quite complex (I will write a special article in this area later), because they can complete some other powerful functions except data access, such as paging and search algorithms. The data access logic is placed on the business layer. Of course, the business layer also contains some other logic code. Let's look at an example. Assume that the database has a table named BOOKS, and a stored procedure named GetAllBooks is created to read the book information. In this way, we compile a method named GetBookS () in the business layer () and a public database category class, GetBooks () opens a connection through the database category class, runs in the stored procedure, and returns data (the return type can be DataTable, DataSet, DataReader or entity class ). The business layer is compiled into one or more DLL files. The presentation layer is followed. The presentation layer binds the returned data to the related control by calling GetBookS. The methods at the service layer are called at the presentation layer. Generally, both book. aspx and book. aspx. cs are the content of the presentation layer. All front-end designs, related controls, and data caches belong to the presentation layer.
2. The data layer also contains all public data access codes.
This mode is not much different from the previous one. It mainly involves six data access codes to the data layer. In this way, multi-database support can be achieved. The business logic layer directly calls the relevant data access code at the data layer, and does not have to know what database is at the underlying layer. There is no difference between others and the previous one.
3. All data reads are placed on the data layer.
In this mode, the GetBooks () method described above is put on the data layer, and a GetBookS () method is defined at the business layer for the presentation layer to call. In this mode, the business layer does not have to know what database is at the underlying layer, but does not even know the database structure. This is the most standard three-tier architecture, which is used in Microsoft's PetShop 4.0.
The above are some of my summary content, which may not be very accurate. Please give me more advice.
Author blog: http://www.cnblogs.com/ewinds/