Let's talk about the evolution of the three-tier architecture

Source: Internet
Author: User

I have a lot of understanding about the layer-3 architecture. The following uses a metaphor for raising pigs to describe what a layer-3 architecture is.

Hierarchies are everywhere in the real world. I remember a joke that a village chief proudly boasted to his wife: "There are only four people in China who are better than my Government, the village chief, the county magistrate, the provincial governor, and the State Council Prime Minister ". This joke also reflects the real social hierarchy. Social groups will be layered, the company's staff structure will also be layered, the building is layered, and even the dumplings are layered. Although the purpose of the hierarchy varies, it is generated to solve a certain problem. Therefore, the layered architecture is actually a solution to solve a problem.

14.1.1 common three-tier Architecture Design

The most common architecture of software systems is the layer-3 architecture. In fact, the entire business application is divided into presentation layer, business logic layer, data access layer, and so on. Some of them need to be more detailed. By decomposing business details, different functional codes are dispersed, which is more conducive to system design and development. At the same time, it provides smaller units for possible changes and facilitates system maintenance and expansion.

The common three-tier architecture consists of the following parts, as shown in figure 14-1.

 

Figure 14-1 Common three-tier architecture

◆ Data access layer DAL: used for interaction and access with the database, obtaining data from the database or saving data to the database.

◆ Business logic layer BLL: the business logic layer is used to process upstream and downstream Interactive Data logically to achieve business goals.

◆ Presentation layer Web: It mainly enables interaction with users, receives user requests or returns the data results of user requests, and submits specific data processing to the business logic layer and data access layer for processing.

In many situations of daily development, in order to reuse common things, some things used at all layers are abstracted. For example, we separate the Data Object entity from the method so that it can be passed in multiple layers, for example, Model. Some common auxiliary classes and tool methods, such as data verification, cache processing, and encryption/Decryption processing, are used as independent modules for reuse between layers, for example, Common.

In this case, the layer-3 architecture is displayed as shown in figure 14-2.

 

Figure 14-2 three-tier Architecture Evolution


◆ Business entity Model: This Model is used to encapsulate entity-class data structures. It is generally used to map database data tables or views and describe objective objects in the business. The Model is separated for better decoupling, better stratified effect, better reuse and expansion, and increased flexibility.

◆ Common Class Library: Common auxiliary tool class.

In section 5.2, we mentioned that common database operations can be abstracted and encapsulated into data operation classes, such as DbHelperSQL, for better reuse and concise code. The underlying layer of the data layer uses the general database operation class to access the database. The complete layer-3 architecture is shown in figure 14-3.

Figure 14-3 final three-tier architecture

The database operations class encapsulates ADO. NET and encapsulates common repeated database operations. For example, Microsoft's enterprise database SQLHelper. cs, dynamic and soft DBUtility/DbHelperSQL, and other tools are provided for DAL to access the database.

Through the above analysis, we know what the common three-tier architecture looks like today. At the same time, we also know some evolutionary processes of the three-tier architecture in use. So why does the layer structure play a role in this way? Let's continue.

14.1.2 interesting understanding: three-tier architecture and pig

According to news reports, this year, pork prices are soaring. It is said that some pigs are becoming richer and better off. programmers all say that coding has no future. It is better to raise pigs. However, don't think that pig pigs have no technical knowledge, which is easier than code writing. In fact, pig pigs are also knowledgeable. To better understand the three-tier architecture, let's take pig farming as an example. As the saying goes: "I have never eaten pork and have never seen a pig run !".

Figure 14-4 shows a three-tier architecture of the swine industry pipeline.

Figure 14-4 three-layer structure and raising pigs

Comparison between figure 14-3 and figure 14-4 shows that:

◆ The database is like a pigsty. All pigs are stored in different pig bars by region or serial number.

◆ DAL is like a slaughterhouse, where pigs are taken out from the pigsty for processing) Slaughter, corresponding part fields are taken out as required), or sort and collect statistics) to form a whole box of pork data sets ), transmitted to the food processing plant BLL ). Originally, the same group of people both caught pigs and killed pigs. Later, they thought the efficiency was too low, so some people came out to take special measures to catch the pigs and DBUtility ), capture the specified pig as required.

◆ BLL is like a food processing factory that processes pork into various edible food services ).

◆ Web is like a mall. It packs food into beautiful products that can be sold and presents them to the customer UI presentation layer ).

◆ Pork is like a Model, no matter which plant layer). The essence of each link is pork, and pork runs through the whole process.

◆ The Common class library is equivalent to a variety of tools used by workers. It provides Common tools for various factory layers, such as pig knives, ropes, scissors, packing boxes, tool carts, and other commonly used tools ). In fact, each department can make its own tools, but this will make the efficiency relatively low, and it is not professional, and a lot of work will be repeated. Therefore, someone has opened such a factory to create these tools and provide them to various factories. With such a division of labor, the factory can concentrate on its own work.

Of course, this is just a metaphor of the image. The purpose is to make everyone better understand it. The actual situation will be different in detail. This example only illustrates the one-way process from pigsty to mall, while data interaction in the actual three-layer development is bidirectional and can be stored. However, it is said that there is a machine that drives the pig in from this end, and the other is grayed out. If the ham cannot be sold, put it in from the end, and the pig comes out of its original version, the sci-fi machine. I didn't expect it to be able to contact the three-tier structure. The above is just a joke, but it also makes the basic concepts of the three-tier architecture easier to understand.

After so many interviews, someone may ask, can I directly retrieve the content from the database for direct operations? Why is it so troublesome to use a three-tier architecture? What are the advantages of a three-tier architecture?

No layering, of course, is like the whole process, regardless of the slaughterhouse, processing site, etc., all in the same place factory) to complete all the live slaughter, processing, sales ). But why processing plants and malls? When the scale is relatively large, the management will become very complicated, and such a breeding method can no longer meet the needs of large-scale development. In addition, from the perspective of social development, social division of labor is a manifestation of human progress. The advantage of social division of labor is to allow suitable people to do what they are good at, greatly shorten the average social labor time, and significantly improve production efficiency. Talents who can provide high-quality and efficient labor products can enjoy high profits and high value in the market competition. The most profound meaning of making full use of things is derived from the social division of labor. The same is true for software development. When it comes to small projects, there is no difference in separation or hierarchy, and it seems more troublesome. However, when the project becomes larger and more complex, the hierarchy shows its advantages. Therefore, the separation layer depends on the actual situation of the project and cannot be generalized.

  1. How to Make ViewState persistent
  2. Common Web services such as weather forecasts and timelines)
  3. . NET Word operation implementation: using Word
  4. Summary of ASP. NET beginners
  5. In-depth research on Repeater controls: Maximum Flexibility

Related Article

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.