Three-tier architecture and pig farming

Source: Internet
Author: User
In order to make it easier for beginners to get started, here are still interesting ways to talk about some common technical points, dedicated. NET Novice's rapid improvement! Knowledge is common, the key is the idea of learning. Technology comes from life, and technology can learn that way. .

Hierarchies are ubiquitous in the real world. Remember a joke about a village head proudly bragging to his wife: "There are only four people in China than my official, township head, county magistrate, Governor and the State Council." This joke also embodies the phenomenon of stratification in the real society. Social groups will be layered, the structure of the company will also be layered, the building is layered, and even make buns of tororo are layered. Although the purpose of layering is different, it is created to solve a problem. Therefore, a layered architecture is actually a solution to solve a problem.

Common three-tier architecture design

The most commonly used software system will talk about the three-tier architecture, in fact, the entire business application is divided into presentation layer, business logic layer, data access layer, and some more fine, through the decomposition of business details, the different function code scattered, more conducive to the design and development of the system, while providing a smaller unit for possible changes, Very beneficial to the maintenance and expansion of the system.

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


Figure 1 Common three-tier architecture

    • data Access Layer DAL: The part that enables you to interact with and access a database, get data from a database, or save data to a database.


    • business Logic Layer BLL: The Business Logic Layer interface, used for the logical processing of the data between the upper and lower interactions to achieve business objectives.


    • Presentation Layer Web: the main implementation and the user's interaction, receives the user request or returns the user request the data result the presentation, but the concrete data processing is handed over to the business logic layer and the data access layer to handle.

In many cases of daily development, in order to reuse something in common, it abstracts the things that are used in each layer. If we separate the data object entities and methods so that they can be passed in multiple tiers, for example called model. Some common general auxiliary classes and tools, such as data validation, cache processing, encryption and decryption processing, in order to allow the reuse of each layer, but also separate out, as a separate module used, for example, called Common.

At this point, the three-tier architecture evolves into 2.


Figure 23 Layer Architecture Evolution Results

    • Business entity Model: Used to encapsulate entity class data structures, typically used to map database tables or views to describe an objective object in the business. The model is decoupled for better decoupling and for better layering, better reuse and expansion, and greater flexibility.


    • General-purpose Class Library common: Generic accessibility class.

We can encapsulate the commonality operation of the database into a data manipulation class (for example, dbhelpersql) to better reuse and make the code concise. The database is accessed using the common database operations class at the bottom of the data layer, as shown in the complete three-tier architecture 3.


Figure 3 Final complete three-tier architecture

  The database access class is an encapsulation of ADO, encapsulating some common duplicate database operations. such as Microsoft's Enterprise Library SQLHelper.cs, soft dbutility/dbhelpersql, etc., for the DAL to provide access to the database of auxiliary tools class.

From the above analysis, we know what the common three-tier architecture is today, and we also know some of the evolutionary processes of the three-tier architecture in use. So, why is this layered, and what does each layer of structure really do? Let's keep looking down.

Fun to understand: three-tier architecture and pig farming

Pork prices all the way up, it is said that some pigs are wealthy Ben well-off, programmers are said to write code has no future, it is better to pig, but do not think that pigs have no technical content, than write code easy, in fact, Pig also has a lot of knowledge. To get a better understanding of the three-tier architecture, take pig-raising as an example. As the saying goes: "Have not eaten pork, have not seen a pig run!" ”。

Figure 4 is a three-layer structured pig industry pipeline fun on this figure.


Figure 43 layer structure and pig raising

In contrast to Figure 3 and Figure 4, we can see:

    • database is like a pigsty , and all pigs are sorted by area or number, stored in different pigsty.


    • dal is like a slaughterhouse , take a pig out of a pigsty to carry out (process) the slaughter, remove the corresponding area (field) as required, or organize (statistics), The whole box of pork (data set) is formed and sent to the food processing plant (BLL). Originally here are the same gang of people both to catch pigs, and to kill pigs, and later felt inefficient, let a part of the people come out to catch pigs (dbutility), according to the requirements to crawl the designated pig.


    • The BLL is like a food processing plant , the pork is processed into a variety of edible food (business processing).


    • The web is like a shopping mall , packaging food into beautiful, ready-to-sell products that are presented to the customer (UI presentation layer).


    • pork is like model , regardless of which plant (layer), the essence of each link is pork, pork throughout the process.


    • General Class Library common is equivalent to a variety of tools used by workers, for each plant (layer) to provide such as kill pig knives, ropes, scissors, boxes, Common tools such as tool carts (classes). In fact, each department could have made their own tools, but that would make the efficiency is lower, but also unprofessional, and a lot of work will be repeated. As a result, the factory will be able to concentrate on its own business by creating such a factory to produce these tools for each factory, with such a division of labor.

Of course, this is just an image metaphor, the purpose is to let everyone better understand that the actual situation in the details will be different. This example also only illustrates the one-way process from pigsty to shopping malls, while the actual three-layer development of data interaction is bidirectional and desirable to be saved. However, it is said that there is a kind of machine, the pig from this head to get in, the other side of the plops out of the ham sausage. If the ham sausage can not be sold, from the head again put in, this pig again out, the sci-fi machine, did not expect to also be able to contact with three layer structure. That's just a joke, but it makes the basic concepts of the three-tier architecture easier to understand.

The above talk about so many, some people will ask, I directly from the database to remove the contents of the direct operation can not it? Why bother using a three-tier architecture? What is the benefit of the three-tier architecture?

Not layering, of course, is like the whole process of the slaughterhouse, processing yard, and so on, all in the same place (factory) to complete all the work (slaughter, processing, sales). But why should processing plants and shopping malls? Because when the scale is relatively large, management will become very complex, such a way of farming can not meet the needs of scale. In view of the social development, the Division of labor is the manifestation of human progress. The advantage of social division of labor is to allow the right people to do their own good things, so that the average society working time greatly shortened, production efficiency significantly improved. To provide high-quality and efficient labor products can be in the market competition to achieve higher profits and high value. The most profound meaning of the best-utilized is the division of labor. Software development is the same, small projects when the sub-stratification does not see what the difference, and appear more troublesome. But when the project becomes larger and more complex, the layering shows its advantages. So the sub-stratification should be based on the actual situation of the project, can not be generalize.

Related documents: Layered development ideas and small steamed buns

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.