Presentation layer - the business logic - Data Access Layer

Reprinted connection:  https://blog.csdn.net/iflychenyang/article/details/9670277

1. What is a three-tier architecture

The so-called three-tier business application development that the whole system is divided into the presentation layer - the business logic - a data access layer, it is a good system development, maintenance, deployment and expansion.

   Layering is to achieve "high cohesion and low coupling." The use of thinking of "divide and conquer", to solve the problem into the open to various, easy to control, easy to extend, easy to allocation of resources.

  •     Presentation Layer: is responsible for direct interaction with the user, generally refers to the interface system for data entry, data display. Means that only the appearance of the display related to the work , not his work not done.
  •    Business logic layer: for doing some validation work to better ensure the robustness of the program run. Specified in the text box does not allow an empty string, the data in the correct format and data type validation;; data, such as completing the addition, modification and inquiry services, etc. to determine the legality of user permissions, etc., many of the above judgment to determine whether the operation passed to the next, as far as possible to ensure the normal operation of the program.
  •    Data Access Layer: As the name suggests, it is used with a special database interaction. Perform data additions, deletions, and other modifications and display. It should be emphasized that all of the data object is only referenced in this layer, such as System.Data.SqlClient, etc., anywhere other than the data layer should not be such a reference.

 ASP.NET can quickly and easily deploy three-tier architecture using the .NET platform. ASP.NET revolutionary change is also used in the web-based event processing, you can specify the code-behind file processing, you can use C #, VB, C ++ and J # as the language code-behind. . The NET can easily achieve the assembly code behind assembly can easily use their components defined by the namespace. ASPX page display layer is placed, database operations and logic layer or packaging component classes to implement, so it is easy to achieve a three-tier architecture.

2. Why use a three-tier architecture

    For a simple application, the code amount is not a lot of cases, a layer structure or a two-story structure developed fully enough, there is no need to complicate, if a large, complex system designed as a layer or structure two-story structure development, then there is a very serious drawback of such a design. The following specific description will, in fact, developed a hierarchical system for large-scale services.

   During development, the primary program staff appear similar functionality often copy the code, then write the same code Why so many? Making the program not only lengthy, but not conducive to maintenance, a small change might involve a lot of pages, often resulting in an abnormal make the program does not run correctly. The main object-oriented thinking has not been the slightest manifestation, under the guise of the name of the object-oriented process-oriented but still walking on the road.

   Aware of this problem, the primary program in the program began some common processing program written in a common method, encapsulated in the class, for other program calls. Such as writing a data operation based on the data manipulation reasonable package, during a database operation, as long as the method (data add, modify, query, etc.) class may perform specific data manipulation, which is the data access layer, not every write operations are those repetitive database operation code database. In the new application development, data access layer can be directly used. Encapsulation of one of the three characteristics of object-oriented here has been well represented. Readers now seems to have found an object-oriented sense, the amount of code than in the past has been greatly reduced, and modify the time is also more convenient, but also to achieve the reusability of the code.

The following two cases, explain why you want to use three-tier architecture.

Case number one:

Database system software due to the increasing amount of data from the Access database into a SQL Server database, so that the original data access layer fails, data manipulation objects has changed, and the pages in place should also be involved in the data object changes, because the original might use OleDbDataReader objects to pass data to display the page, now had to be replaced SqlDataReader object, SQL Server and Access data types supported by inconsistent data conversion performed when displaying data should be modified, this is one of the Happening.

Case II:

Special circumstances so require, to transform the project into a Web form Windows application, this time how much needs to be done to modify it? If you take a lot of code in Aspx.cs in, or there are some code exists in the Aspx, then the entire system is needed to re-develop it?

 

   In the above case whether the defect did not understand the hierarchical development model it? Whether you encountered such a situation? This is caused by a poorly designed, developed a multi-layer appearance architecture can solve this problem, stratified by reasonable procedural framework, will greatly improve the versatility of the program.

3. The advantage of using three-tier architecture development

Use three-tier architecture development has the following advantages:

  •    From the perspective of the development and application point of view, than the second floor of the three-tier architecture, or a single-layer architecture has a greater advantage. Three-tier architecture for team development, each person can have a different division of labor, work together to make productive. When developing or two-story single-layer application, each developer has to deal with a deeper understanding of the system, high capacity requirements, while developing three-tier applications, you can combine a wide range of talent, just a few people on the system overall Learn to reduce the difficulty of development to some extent.
  •    Three-tier architecture can better support distributed computing environments. Application logic layer may run on multiple computers, using the calculated full-function network. The great potential of distributed computing, CPU upgrades than effective. Americans have been calculated using the fractional decryption, a few months can not always break the alleged crack the password.
  •    The biggest advantage is its three-tier security. Only be accessed via a user data logical layer level, the entry point is reduced, the risk of many system functions are blocked.

4. Kind of three-tier architecture

Currently, the team developers in the development of projects, mostly developed using a layered architecture design, the most common is the three-tier architecture, the purpose is to make between the various layers can only be its impact on adjacent layers, but this limit is often in when using multi-layered development is violated, the development of this system is harmful. Three-tier architecture according to the drive mode can be divided into three types: data layer drive mode, drive mode and isolation presentation layer drive mode, in which the isolated driver model development is most important. By comparison of the following three modes, describes the importance of isolation driving mode.

 

   Data layer drive mode

   The so-called data layer drive mode is to first design the data layer, presentation layer revolve around data layer, upon completion of the data layer and the presentation layer, the business layer will revolve around the data layer. Because the statements layer is revolves around the data layer, which will make the presentation layer constraint inaccurate and limits Changes in the business layer. As the business layer is limited, some simple changes can be achieved through SQL queries and stored procedures.

   This pattern is very common, and it is traditional customer service similar side development, and is designed around a database that already exists. Because the data presentation layer around the layer design, it is often intuitively mimic the actual data layer structure.

 

   There is often an additional set forth in the feedback loop between the data layer, presentation layer, when the design is often not easily achieved to modify the data layer, which also formed a feedback loop. Developers request to modify the database layer to facilitate the development of a statement, but the design of the data layer is harmful. This change is man-made and did not take into account other needs of the restrictions. This modification often violate the rules specific to least damage data, resulting in non-standardized unnecessary data redundancy and data.

    Presentation layer drive mode

   Presentation layer drive mode is the data layer that surrounds the statements layer expanded. Complete the business layer is typically a simple SQL queries and little change or isolation. Because of the design of the database is to facilitate the presentation layer, not from the data layer design considerations, the design of the database is usually low in performance. Presentation layer design driving mode is shown in Figure 1.6.

 

   Isolation drive mode

    Separator drive mode design, presentation and data layers developed independently, it is often developed in parallel. The two layers without any mutual interference in the design, so there is no harmful artificial constraints and design elements. When the layers are designed, redesign business layer. Responsibility for the business layer is to complete all of the conversion on the basis of no demand for data layer and the presentation layer changes on. Design presentation layer drive mode.

 

    Because now presentation layer and the data layer is completely independent, when business needs change layer, presentation layer and the data layer can be modified accordingly without affecting each other. Two changes are not physically adjacent layer does not directly affect other layers or conflict. This allows adjustment of the data or the presentation layer of the layer structure changes accordingly based on the user's requirements without the need to modify the system to adjust or bigger. Table 1.1 of these three drive modes will be compared.

Species Comparison Table driving mode

  

Data layer drive mode

Presentation layer drive mode

Isolation drive mode

database

(1) it is easy to design

(2) have a negative impact

(3) difficult to change the data layer and the presentation layer because it is tightly bound

(1) bad database design

(2) standardization of design is not serious

(3) other systems difficult to use

(4) data layers difficult to change, because it is tightly bound with statements layer

(1) Design Optimization

(2) centralized database design, it has little effect presentation layer

Business needs

Often can not adapt to changing business needs

Often adapt to changing business needs

Adapt to changes in demand

User Interface

Around the user rather than around the data layer, difficult to modify

User interface for expansion

User interface for expansion

Expansibility

Typically expandable, but need more often rewritten in the user interface to meet the structure of the database, the database may need to store simultaneously a number of redundant fields

The integrity of the expansion is difficult, often only be achieved by "cut and paste" function

Can be easily extended

     In summary, it is easy to see the advantages of isolated drive mode, the drive mode isolation design can greatly improve the scalability of the program. In Section 1.3.2 of the application on the use of the three-tier isolation drive mode.

 

 

Released six original articles · won praise 189 · views 280 000 +

Guess you like

Origin blog.csdn.net/newbie_xymt/article/details/103969518