C # 83-tier architecture enterprise applications

Source: Internet
Author: User

1.1 Introduction to three-tier architecture

If you are running a big hotel, in general you will ask three people, on the one hand is responsible for hotel service waiter, on the other hand is responsible for cooking, cooking cooks, on the one hand is responsible for hotel vegetables, meat, spices and other buyers.


If you do, then the restaurant management, it is better management (simple). For example, any one of the employees in the absence or leave the situation, you can find other waiters, cooks or buyers instead.

In the enterprise this separation of duties, business independent division method for the management of enterprises have great benefits, the same in the procedure also need to use "separation of duties, business independent" principle division module, better realize "high cohesion, low coupling" software design idea.

1.2 Why use a three-tier architecture

So why should we use layered development, and what is the unique advantage of it?

. NET development platform for our development to provide a strong technical support, so that our development has become very convenient and efficient. With the strong support of code behind, we can effectively separate page design from code design, code writing, and page design at the same time.

It is true that we have done very well on the basis of functional implementation, especially for a simple application where the amount of code is not a lot, and this layer of structural development is fully sufficient, and there is no need to complicate it. But the flaws in this design are serious for a large, complex system.

During the development process, we keep copying the code around to achieve some similar functionality. Why did the same code have to be written so many times? Not only does the program become lengthy, but it is also less maintainable, and a small change may ripple through many pages. A little inattention can result in an exception, which prevents the program from running properly. The most important object-oriented ideas have not been reflected in the slightest, but the face of object-oriented is still walking the old way of facing the process.

Aware of such a problem, I began to write some common handlers in the program as public methods encapsulated in the class for other programs to invoke. Like some functional code collection, database operation, like SqlHelper to the data operation reasonable encapsulation, SQL statement, parameter list as parameters, in the database operation process, as long as the corresponding parameters can be completed in the specific data operations, this is my first data access layer, You don't have to write repetitive database operations code every time you manipulate the database. In the new application development, the data access layer can be used directly.

The encapsulation of one of the three main features of object-oriented has been well embodied here. Seems to find the object-oriented sense, the code is much less than before, and the time to modify is also more convenient. Is this supposed to be all right?

If one day the database vendor changes, because of the increase in the amount of data, the database has access turned into SQL Server? This is a big trouble, the original data access layer failed, the data manipulation objects have changed, and the page involved in the data object is also to be modified, because the original may use the OleDbDataReader object to pass data to the display page, now have to be replaced by SqlDataReader object, The data types supported by SQL and access are also inconsistent, and the data conversions that are performed when the data is displayed may also be modified. The transformations made by SQL to access are more modified.

There is also a situation where, because of some need, we want to transform a web-like project into a Windows application, how much modification is involved? If you put a lot of processing code in your aspx.cs, or some of the code exists in ASPX, there is no aspx in the Windows app, is the entire system needed to be restarted? This is all a curse of unreasonable design.

1.3 Composition of the three-tier architecture

We typically say that the three-tier architecture contains the presentation layer, the business layer, and the data layer three layer, for the application system, the presentation layer and user interaction and display the data, the business layer is responsible for accessing the data layer and submitting data to the presentation layer, the data layer is responsible for the storage of data. The following is a detailed description of the meaning and composition of the three-tier architecture:

n Represents a layer

It mainly refers to the interface that interacts with the user, it receives the user's input, but does not include any actual business processing, it simply tells the data to the business layer, but also is responsible for showing the business layer passes over the data, when the background business logic updates, the presentation layer displays these updates. The presentation layer provides the user interface (UI) for the application, typically including Windows Forms, Asp.netweb forms.

N Business Layer

It represents the core functionality of the application, handles data at the data layer, implements business logic, and implements the business process of a certain rule to match the needs of a particular company. For example, a business rule that determines whether a specified customer is approved for a lending activity can be encapsulated in a customer business component of a small solution. For large solutions, all lending-related business logic may be encapsulated in a separate borrowing component.

N Data Layer

Data Access layer: sometimes referred to as the persistence layer, its function is mainly responsible for database access, access to the database system, binary files, text documents or XML documents. The simple argument is to implement the select,insert,update,delete of the data table. If you want to add an ORM element, it will include the mapping between the object and the data table, and the persistence of the object entity.

The figure for comparing the three-tier architecture to the various staff layers in the hotel is as follows:

Advantages of three-layer structure

1) from a development perspective and application perspective, the three-tier architecture has a greater advantage than a double or single-layer structure. Three-layer structure suitable for group development, each person can have different division of labor, work together to make efficiency doubled. When developing a double or single-layer application, each developer should have a deep understanding of the system, the ability requirements are high, the development of three-tier applications, you can combine a variety of talents, only a few of the system to understand the overall, from a certain degree of work to reduce the development of the difficulty

2) Three-tier architecture provides better support for distributed computing environments. The logic layer of the application can be run on multiple machines, taking full advantage of the network's computational capabilities. The potential for distributed computing is huge, far more effective than upgrading CPUs. The Americans used the fractional calculation to decrypt, and in a few months they cracked the code that was allegedly never broken.

3) also the biggest advantage of the three-tier architecture is its security. The client can access the data layer only through the logical layer, reducing the entry point and shielding many dangerous system functions.

disadvantages of the three-layer structure
"Gold is no can't pure, nobody is perfect", the layered structure also inevitably has some defects:
1, reduce the performance of the system. This is self-evident. Without a tiered structure, many businesses can access the database directly to get the data, and now they have to do it through the middle tier.
2. Sometimes cascade changes are caused. This kind of modification is especially reflected in the top-down direction. If you need to add a feature in the presentation layer to ensure that the design conforms to the layered structure, you may need to add code to the appropriate business logic layer and the data access layer.

Building a three-tier architecture




2.2 Click New Item -", select, application configuration file

2.3 After opening the App. config file, write the following code:







/* This first weakens, the business logic layer */

6th Step: Presentation Layer




In this way, the entire complete, simple three-tier framework login has been basically completed.

Please do not complete the students follow this step, be sure to finish. Experience the invocation and relationship of classes between layer three frameworks.

/* For each "Related liability class" in layer three, add breakpoints, test, and see the effect of parameter passing. */

The following students, connect the project leader's database server.



Open TCP/IP and other services





Summary:

What is the difference between the N three-layer structure and the two-storey structure?

n Why do you want to implement tiering? What are the roles of each layer?

How is the interdependence of the layers in n three-tier structures implemented?

Homework:

based on the former hotel management system, car sales system, such as C/s system, according to the three-layer architecture of the idea, re-build a new framework.



C # 83-tier architecture enterprise applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.