In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Xiaobian to share with you PetShop system architecture design example analysis, I believe most people do not know how, so share this article for your reference, I hope you read this article after a lot of harvest, let us go to understand it!
1. PetShop System Architecture Design
Layered structure is the most common and important structure in software architecture design. The hierarchical structure recommended by Microsoft is generally divided into three layers, from bottom to top: data access layer, business logic layer (or domain layer), presentation layer, as shown in the figure:
Figure 1: Three-tiered structure
Data Access Layer: Sometimes referred to as the Persistence Layer, its function is primarily responsible for database access. Simply put, select, Insert, Update, Delete operations on the data table. If you want to add elements of ORM, you will include mapping between objects and data tables, and persistence of object entities. In PetShop's data access layer, ORM is not used, resulting in an increase in code volume, which can be seen as a major failure in the overall design implementation.
Business logic layer: It is the core of the whole system, and it is related to the business (domain) of this system. Take PetShop as an example, the relevant design of the business logic layer is related to the logic unique to online pet shops, such as querying pets, placing orders, adding pets to shopping carts, etc. If database access is involved, the data access layer is invoked.
Presentation Layer: The UI part of the system responsible for user interaction with the system as a whole. In this layer, the ideal state is that the business logic of the system should not be included. Represents the logic code in the layer and relates only to interface elements. PetShop is designed using ASP.Net and therefore contains many Web controls and related logic.
What are the advantages of hierarchical structure? Martin Fowler, Patterns of Enterprise Application Architecture:
Developers can focus on only one layer of the overall structure;
2. It is easy to replace the implementation of the original level with a new implementation;
3, can reduce the dependence between layers;
4. It is conducive to standardization;
5, conducive to the multiplexing of each layer of logic.
In summary, hierarchical design can achieve the following goals: decentralized attention, loose coupling, logical reuse, standard definition.
A good hierarchical structure can make the division of labor clearer for developers. Once the interfaces between the layers are defined, developers responsible for different logical designs can split their focus and work in tandem. For example, UI designers only need to consider the user interface experience and operation, domain designers can only focus on the design of business logic, and database designers do not have to worry about cumbersome user interaction. With each developer's task identified, development progress can be improved rapidly.
The benefits of loose coupling are obvious. If a system is not layered, then the logic of each is tightly intertwined and interdependent, and none of them is replaceable. Once the change occurs, it will affect the whole body, and the impact on the project is extremely serious. Reducing the dependency between layers can not only ensure future scalability, but also have obvious advantages in reusability. Once a unified interface is defined for each functional module, it can be invoked by individual modules rather than being developed repeatedly for the same functionality.
Standards are also essential for good hierarchical design. The system is scalable and replaceable only if it is standardized to a certain extent. Communication between layers also ensures standardization of interfaces.
"No gold is perfect, no one is perfect," and the hierarchical structure inevitably has some defects:
1) Reduced system performance. This is self-evident. Without a hierarchical structure, many businesses could access the database directly to retrieve the corresponding data, but now they must do so through the middle tier.
Sometimes it leads to cascading modifications. This modification is particularly reflected in the top-down orientation. If you need to add a feature to the presentation layer, you may need to add code to both the business logic layer and the data access layer to ensure that the design conforms to the hierarchical structure.
As mentioned earlier, PetShop's presentation layer is designed with ASP.Net, that is, it should be a BS system. In. Net, the standard BS hierarchical structure is shown below:
Figure 2: Standard BS hierarchical structure in. Net
With the update of PetShop version, its hierarchical structure is also constantly improving, for example, PetShop 2.0 does not adopt the standard three-tier structure, as shown in Figure 3:
Figure 3: PetShop 2.0 Architecture
As we can see from the diagram, there is no obvious data access layer design. While this design improves data access performance, it also leads to confusion between the business logic layer and the responsibilities of data access. Once the database required to support it changes, or the logic of data access needs to be modified, this can lead to major changes in the project due to the lack of clear layering. With the improvement of hardware system performance and the full use of cache, asynchronous processing and other mechanisms, the performance impact of hierarchical structure can be ignored.
PetShop 3.0 corrects the previously unclear hierarchy by separating the data access logic as a separate layer:
Figure 4: PetShop 3.0 Architecture
PetShop 4.0 basically continues the structure of 3.0, but has made some improvements in performance, introducing caching and asynchronous processing mechanisms, and making full use of ASP.Net 2.0's new feature MemberShip. Therefore, PetShop 4.0's system architecture diagram is as follows:
Figure 5: PetShop 4.0 architecture
Comparing the system architecture diagrams of 3.0 and 4.0, the core content has not changed. In the data access layer (DAL), the DAL Interface is still used to abstract the data access logic, and the DAL Factory is used as the factory module of the data access layer object. For DAL Interface, there are SQL Server DAL supporting MS-SQL and Oracle DAL supporting Oracle implementations. The Model module contains data entity objects. The detailed module structure diagram is shown as follows:
Figure 6: Module structure diagram of data access layer
As you can see, in the data access layer, the idea of "interface oriented programming" is fully adopted. The IDAL module abstracted out is separated from the dependence on the specific database, so that the whole data access layer is conducive to database migration. The DALFactory module specifically manages the creation of DAL objects for easy access by the business logic layer. SQL Server DAL and OracleDAL modules both implement the IDAL module interface, which contains logic for database operations such as Select, Insert, Update and Delete. Because the database type is different, the operation on the database is also different, and the code will therefore be different.
In addition, the abstracted IDAL module, in addition to removing downward dependencies, also has only weak dependencies on the business logic layer above it, as shown in the following figure:
Figure 7: Module structure diagram of business logic layer
The BLL in Figure 7 is the core module of the service logic layer, which contains the core services of the entire system. In the business logic layer, the database cannot be accessed directly, but must be accessed through the data access layer. Note that the invocation of the data access service in the figure is accomplished through the interface module IDAL. The relationship between layers is loosely coupled since it is independent of the specific data access logic. If the specific implementation of the data access layer needs to be modified at this time, the business logic layer will not be affected as long as the interface definition of IDAL is not involved. After all, the SQL Server DAL and Oracle DAL implementations have nothing to do with the business logic layer.
Because asynchronous processing was introduced in PetShop 4.0. The strategy of inserting orders can be divided into synchronous and asynchronous, the insertion strategy of the two is obviously different, but for the caller, the interface of inserting orders is exactly the same, so the IBLLStrategy module is designed in PetShop 4.0. Although the IBLLStrategy module is simply an IOrderState, it also gives an example and information that abstract principles should be used in the processing of business logic if there is a diversity of business operations or possible future changes. Either interfaces are used or abstract classes are used to break away from business dependencies. However, in PetShop, due to the relatively simple business logic, this idea is not obvious enough. Because of this, PetShop puts the core business logic into a module BLL, and does not separate the specific implementation and abstraction strictly according to the module. Therefore, the invocation relationship between the presentation layer and the business logic layer has a relatively high degree of coupling:
Figure 8: Module structure diagram representing layers
In Figure 5, auxiliary modules are also introduced into each hierarchy, such as the Messaging module of the data access layer, which provides the function of inserting orders asynchronously and adopts Microsoft Messaging Queue technology. CacheDependency at the presentation layer provides caching functionality. These special modules will be described in detail in subsequent articles.
The above is "PetShop system architecture design sample analysis" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.