Advanced skills in system architecture design · Hierarchical architecture design theory and practice

现在的一切都是为将来的梦想编织翅膀,让梦想在现实中展翅高飞。
Now everything is for the future of dream weaving wings, let the dream fly in reality.

Click to enter the series of articles directory

Insert image description here

1. Overview of hierarchical architecture

1.1 Definition

Software architecture can be defined as: Software architecture provides a high-level abstraction of the structure, behavior, and properties of a software system and consists of a description of the elements that make up the system, the interactions of these elements, the patterns that guide the integration of the elements, and the constraints of these patterns. Software architecture not only specifies the organizational structure and topology of the system, but also shows the correspondence between system requirements and the elements that make up the system, provides some basic principles for design decisions, and is a system-level complex built on the software system. use.

The layered architecture is the most common architecture design method, which can effectively simplify the design, make the designed system structure clear, and facilitate the improvement of reusability and product maintenance capabilities. Hierarchical architecture design is to organize the system into a hierarchical structure, with each layer serving the upper layer and acting as a lower-layer customer. In some hierarchical systems, except for a few carefully selected output functions, internal layer interfaces are only visible to adjacent layers. Connectors are defined by protocols that determine how layers interact, and topological constraints include constraints on interactions between adjacent layers. Since each layer only affects two layers at most, and as long as the same interface is provided to adjacent layers, each layer is allowed to be implemented in different methods, which also
provides powerful support for software reuse.

1.2 Composition of hierarchical applications

Insert image description here

1.3 Features and precautions

2. Presentation layer framework design

2.1 MVC (Model-View-Controller) pattern

MVC is a software design pattern. MVC separates the input, processing, and output processes of an application in terms of view, control, and model, forming three core modules of controller, model, and view, among which: (1) Controller: accepts user
input , and call models and views to complete user needs.
(2) Model: The main part of the application, representing business data and business logic.
(3) View: The interface that users see and communicate with.

As shown in the figure, the collaborative relationship between the three:
Insert image description here
using the MVC pattern to design the presentation layer can have the following advantages:
(1) Allows the expansion of a variety of user interfaces.
(2) Easy to maintain.
(3) Easy to build a powerful user interface.
(4) Increase the scalability, robustness, and flexibility of applications.

2.2 MVP (Model-View-Presenter) mode

In the MVP mode, the Model provides data, the View is responsible for display, and the Controller/Presenter is responsible for logical processing. MVP not only avoids the coupling between View and Model, but also further reduces the Presenter's dependence on View.

As shown in the figure, MVP design pattern:
Insert image description here
Using the MVP pattern to design the presentation layer can have the following advantages:
(1) The model is completely separated from the view, and the view can be modified without affecting the model.
(2) All interactions occur in one place - inside Presenter, so the model can be used more efficiently.
(3) You can use one Presenter for multiple views without changing the Presenter's logic. Because the view always changes more frequently than the model.
(4) If you put the logic in the Presenter, you can test the logic (unit testing) without the user interface.

2.3 MVVM (Model-View-ViewModel) pattern

MVVM is similar to MVC and MVP, and its main purpose is to achieve the separation of views and models. The difference is that in MVVM, the interaction between View and Model is realized through ViewModel, that is, View and Model cannot communicate directly, and the communication between the two can only be realized through ViewModel. ViewModel is the core of MVVM. It realizes two-way binding between View and Model through DataBinding, which includes data status processing, data binding and data conversion.
As shown in the figure, MVVM design pattern:
Insert image description here

3. Middle layer framework design

3.1 Business logic layer component design

Business logic layer components are divided into two parts: interface and implementation class. Interfaces are used to define business logic components. Defining the methods that business logic components must implement is the core of the entire system operation. Business logic components are usually designed according to modules. Each module is designed with a business logic component, and each business logic component uses multiple Data Access Object (DAO) components as the baseline to provide the system's business logic services to the outside world. .

3.2 Business logic layer workflow design

The Workflow Management Coalition (WFMC) defines workflow as: the full or partial automation of business processes. In this process, documents, information or tasks flow according to certain process rules to achieve coordination among organizational members. Achieve the overall goals of the business.

As shown in the figure, the workflow reference model:
Insert image description here

3.3 Business logic layer entity design

Logic layer entities provide stateful programmatic access to business data and related functionality (in some designs). Business logic layer entities can be built using data with complex schema, often coming from multiple related tables in a database. Business logic layer entity data can be passed as part of the I/O parameters of the business process. Business logic layer entities are serializable to maintain their current state.

3.4 Business logic layer framework

The business logic framework is located in the middle layer of the system architecture and is the core component for realizing system functions. It adopts the form of container to facilitate the development, code reuse and management of system functions. In the business container, business logic is implemented according to the Domain Model-Service-Contro idea. Among them:
(1) Domain Model is a domain layer business object that only contains business-related attributes.
(2) Service is an integral part of the business process implementation and is a different functional unit of the application program, which is connected through well-defined interfaces and contracts between these services.
(3) Control service controller is the link between services, and switching between different services is achieved through it.

4. Data access layer framework design

4.1 Data access mode

(1) Online access
(2) Data Access Object
(3) Data Transfer Object
(4) Offline data mode
(5) Object/relationship mapping

4.2 Application of factory pattern in data access layer

This requires encapsulation of these database access classes again during the actual development process. After such encapsulation, not only can the above goals be achieved, but also the steps to operate the database can be reduced, and the amount of code writing can be reduced. Factory design pattern is the main method used.

The factory pattern defines an interface for creating objects and lets subclasses decide which class to instantiate. Factory methods enable deferring instantiation of a class to its subclasses. Operations on multiple databases may be handled here, so you need to first define an interface for manipulating the database, and then the class factory decides which class to instantiate based on the database.

4.3 ORM, Hibernate and CMP2.0 design ideas

ORM (Object-Relation Mapping) makes a mapping between a relational database and an object. In this way, when specifically manipulating the database, you no longer need to deal with complex SQL statements, and you only need to operate as you normally do with objects. When developing an application (without using OR Mapping), it may involve a lot of code in the data access layer, which is used to save, delete and read object information from the database, etc. However, these codes are always repeated when written. A better way is to introduce OR Mapping. Essentially, an OR Mapping generates DAL. Instead of writing DAL code yourself, it is better to use OR Mapping. Developers only need to care about the objects.

4.4 XML Schema

XML Schema is used to describe the legal structure, content and restrictions of XML documents. XML Schema is self-describing by XML 1.0 and uses namespaces. It has rich embedded data types and powerful data structure definition functions, fully transforming and greatly extending DTDs (traditional description of XML document structure and content restrictions). mechanism), will gradually replace DTDs and become the formal type language in the XML system. Together with the XML specification and the Namespace specification, it will become the solid foundation of the XML system.

4.5 Transaction processing design

Transaction is one of the core concepts in modern database theory. If a set of processing steps either all occur or none is executed, we call the set of processing steps a transaction. When all steps are completely executed as one operation, we say the transaction is committed. Because one or more steps fail and no steps are committed, the transaction must be rolled back (return to the original system state). Transactions must comply with the ACID principles established by ISO/IEC. ACID is the abbreviation for Atomicity, Consistency, Isolation and Durability. The atomicity of a transaction means that any failure during transaction execution will cause any modifications made by the transaction to become invalid. Consistency means that when a transaction fails, all data affected by the transaction should be restored to the state before the transaction was executed. Isolation means that modifications to data during transaction execution are not visible to other transactions before the transaction is committed. Persistence means that the status of the submitted data should be correct when the transaction execution fails.

4.6 Connection object management design

For shared resources, there is a very famous design pattern - resource pool. This model is designed to solve the problems caused by frequent allocation and release of resources. Applying this model to the field of database connection management is to establish a database connection pool and provide a set of efficient connection allocation and usage strategies. The first step in establishing a connection pool is to establish a static connection pool. The so-called static means that the connections in the pool are allocated during system initialization and cannot be closed at will. With this connection pool, a set of customized allocation and release strategies can be provided below. When a client requests a database connection, it first checks whether there are unallocated connections in the connection pool. If there is an idle connection, the connection is assigned to the client and processed accordingly.

5. Data architecture planning and design

5.1 Integration of database and class design

The correct identification of classes and relationships between classes is the key to data models. This section discusses how to discover, identify, and describe classes. It is impossible to reduce the modeling process to a simple, step-by-step process. At its core, modeling is an art. There is no single correct data model for a given complex situation, but there are good data models. One data model for an enterprise or institution may be better than another, but there is no single solution for how to model a data model for a particular system.

The goal of a good model is to minimize the cost over the entire life of the project, while also taking into account possible changes in the system over time, so the design should also consider adapting to these changes. Therefore, it is a mistake to focus on minimizing development expenses.

5.2 Integration of database design and XML design

XML documents are divided into two categories: one is data-centered documents, which are regular in structure, isomorphic in content, have less mixed content and nested levels, and people only care about the document The data in the document does not care about the storage order of data elements. This kind of document is called a data document for short. It is often used to store and transmit Web data. The other type is document-centered documents. This type of document has an irregular structure, scattered content, more mixed content, and the order between elements is related. This type of document is often used to publish descriptions on web pages. Sexual information, product performance introduction and E-mail information, etc.

There are two ways to store XML documents: file-based storage and database storage.

6. Hierarchical architecture design of the Internet of Things

  • (1) Perception layer:
    The perception layer is used to identify objects and collect information. The perception layer includes QR code tags and readers, RFID tags and readers, cameras, GPS, sensors, M2M terminals, sensor gateways, etc. Its main function is to identify objects, collect information, and the role of skin and facial features in the human body structure similar.

  • (2) Network layer:
    The network layer is used to transmit information and process information. The network layer includes the integrated network of communication network and Internet, network management center, information center and intelligent processing center. The network layer transmits and processes the information obtained by the perception layer, similar to the nerve center and brain in the human body structure.

  • (3) Application layer:
    The application layer realizes extensive intelligence. The application layer is the deep integration of the Internet of Things and industry expertise, and combines industry needs to achieve industry intelligence, which is similar to people's social division of labor.

Click to enter the series of articles directory

Guess you like

Origin blog.csdn.net/weixin_30197685/article/details/132515422