What is architecture
Software designers who have high technical skills and rich experience need to design the architecture of the software system, that is to say, we need to design how the system's components are divided, how components interact, and how logical, physical, and important decisions are made in the system. In many companies, architects are not specialized and formal roles. Generally, the most experienced programmer in a Development Group is responsible for some architectural work. The most experienced project manager in a department is responsible for some architecture work. However, more and more companies recognize the importance of architecture work.
What is the architecture of a software system )? Generally, the architecture has two elements:
· It is the highest level of division of a software system from the whole to the part.
A system is usually composed of components, and how these components form and interact with each other is an important information about the structure of the system.
Specifically, it includes architecture components, connectors, and task-flow ). The so-called architecture element is the core "brick" of the system, and the connector describes the path of communication between these components, the mechanism of communication, and the expected results of communication, the task flow describes how the system uses these components and connectors to fulfill a requirement.
· The highest level of commercial and technical decisions made by building a system that will be difficult to change in the future.
There are many important decisions that need to be made prior to building a system. Once the system starts to be designed or built in detail, these decisions are hard to change or even unable to be changed. Obviously, such a decision must be the most important decision on the success or failure of system design and must be carefully studied and investigated.
The history of Computer Software began in 1950s, and its history was very short. In contrast, construction engineering started from the Stone Age, and humans have accumulated a lot of experience and lessons in architectural design practices for thousands of years. Architectural Design basically includes two points: architectural style and architectural model. The unique architectural style and the appropriate architectural model can be unique.
The pictures below show the ancient Maya buildings in Central America, the Great Pyramid of Chichi-Itza, and the 9-Eleven steps (representing the days of the Four Seasons, the temple on the top of the tower lingers into the clouds. All the numbers are as rigorous as calendars, and the style is vigorous. It is hard to imagine that this is a stone-age building.
Figure 1. The ancient Maya building is located in chichei-Itza, Mexico (in the Maya language, Chi indicates the mouth Chen indicates the well. (Photography: author)
The relationship between software and human beings is the core issue that architects must face. It is also a problem that has occurred since the software entered the stage of history. Like this, the relationship between architecture and human beings has been the core issue that architects must face since building. British Prime Minister Churchill said that we constructed a building and then constructed us (we shape our buildings, and afterwards our buildings shape us ). The conference hall in the lower House of Commons is narrow, so that all members of the lower House of Commons cannot be seated in the same direction, but must be divided into two sides. Churchill believes that Members of Parliament will naturally choose to sit at the same time as their political views, which refer to the origins of British political parties. The original intention of party is "fang" and "face ". The key to the origins of political parties is the influence of buildings on people.
In the software design field, many people think that the function is the most important, and the form must obey the function. Like this, Louis Sullivan, one of the creators of modern architecture schools in the architectural field, also believes that the form should be subject to the function (Forms follows function ).
Almost all software design concepts can find more distant historical echoes in the vast history of architecture. The most famous, of course, is the model theory and XP theory.
What is the goal of the architecture?
Just as the software has its own goals, what are the goals of architecture design? In general, the software architecture design should achieve the following goals:
· Reliability ). Software systems are extremely important for users' business operations and management. Therefore, software systems must be very reliable.
· Secure ). The business value of the transactions undertaken by the software system is extremely high, and the security of the system is very important.
· Scalable ). The software must be able to maintain reasonable performance when the user's usage and number of users increase rapidly. Only in this way can we adapt to the possibility of expanding the user's market.
· Customizable ). The same set of software can be adjusted based on different customer groups and changes in market demands.
· Extensible ). When the emergence of new technologies, a software system should allow the import of new technologies to expand the functions and performance of existing systems.
· Maintainable ). Maintenance of software systems includes two aspects: first, to eliminate existing errors, and second, to reflect new software requirements to existing systems. An easy-to-maintain system can effectively reduce the cost of technical support
· Customer experience ). Software systems must be easy to use.
· Time to market ). Software Users must face intra-industry competition, and software providers must also face intra-industry competition. It is very important to compete for market opportunities as quickly as possible.
Architecture type
Based on our concerns, we can divide the architecture into three types:
· Logical architecture, relationships between components in software systems, such as user interfaces, databases, external system interfaces, and commercial logic components.
For example, the following figure shows the logical architecture of a software system that I have personally experienced.
Figure 2. Example of a logical architecture
From the figure above, we can see that the system is divided into three logical layers: appearance level, business level and data persistence level. Each layer contains multiple logical components. For example, the web server layer includes HTML service components, session service components, security service components, and system management components.
· How the physical architecture and software components are put on the hardware.
For example, the following physical architecture diagram describes the physical architecture of a distributed system distributed in Beijing and Shanghai. All the components in the diagram are physical devices, including Network Shunt, proxy server, web server, application server, Report Server, consolidation server, storage server, host, and so on.
Figure 3. A physical architecture example
· System architecture and non-functional features of the system, such as scalability, reliability, robustness, flexibility, and performance.
The design of the system architecture requires the architect to have excellent knowledge of the functions and performance of software and hardware, which is undoubtedly the most difficult task in architecture design.
In addition, from each perspective, we can see two elements of the Architecture: component division and design decision.
First, components in a software system are logical components first. How these logical components are put on the hardware, and how they contribute to the scalability, reliability, robustness, flexibility, and performance of the entire system are very important information.
Second, the decisions that need to be made for software design will inevitably include the logical structure, physical structure, and how they affect all the non-functional features of the system. Many of these decisions are hard to be changed once made.
Based on the author's experience, a database-based system architecture, how many data tables will be there on how many pages of architecture design documents. For example, a medium database application system usually contains about one hundred data tables. Such a system design usually requires about one hundred pages of architecture design documents.
Architect
Software designers who have high technical skills and rich experience need to design the architecture of the software system, that is to say, we need to design how the system's components are divided, how components interact, and how logical, physical, and important decisions are made in the system.
Such a person is called an architect ). In many companies, architects are not specialized and formal roles. Generally, the most experienced programmer in a Development Group is responsible for some architectural work. The most experienced project manager in a department is responsible for some architecture work.
However, more and more companies recognize the importance of architecture work and set specialized architect positions at different organizational levels, they are responsible for the design, configuration, and maintenance of logical architecture, physical architecture, and system architecture at different levels.
Software Architecture Design
A good start is half the success
The initial architecture design determines the survival of software products. "A good start is half the success ".
The initial architecture design is also the most difficult. We need to investigate the situation and technical characteristics of similar products and learn about the theoretical support and technical platform support provided by such products in the world. Combined with the characteristics of your project (a thorough system analysis is required), you can gradually form the Architecture Blueprint of your project.
For example, to develop a website engine system, you can go from the Yahoo personal homepage generation tool to the website automatic generation system provided by the web hosting service provider, as well as the features and limitations of the IBM webbench portal, you can determine the location of your product from the perspective of architecture design.
A good design must be modified repeatedly. from simple to complex cyclic testing is a good way to ensure correct design.
Since the right direction was selected at the beginning, the implementation process of the project also verified this option. However, the solution needs to be modified in some architectural design details, it belongs to the method of spiraling up. Obviously this is achieved through the idea of testing first and the XP engineering method.
If our initial architecture design has a certain level of world-class positioning on the technical platform, half of the project development practices are equivalent to doing experiments, R & D, and there are considerable technical risks.
Therefore, it is impossible for us to implement every requirement at the beginning, but to adopt a simple method to complete the architecture process, the simplest requirement is to simply complete the entire architecture (with manual intervention ), in order to check whether the technical links can coordinate and cooperate with each other (two excellent and advanced technologies sometimes cannot work together), you can also find out the depth of the technology and grasp the technical difficulties of the project. After this process is completed, we made the above major changes to the design scheme, enriched and improved the design scheme.
The design pattern is an important component supporting the architecture.
Architecture Design is similar to a kind of workflow, which is dynamic. Unlike architectural design, the architecture design can be completely determined from the very beginning. The architecture design is accompanied by the entire project process, there are two specific operations to ensure the correct completion of the architecture design, that is, the design mode (static) and the engineering project method (RUP or XP dynamic ).
The design mode is an important component supporting the architecture, which is similar to the building. To build a building, the design of the building architecture is required. During the specific construction, there are many architectural rules and patterns.
We use the J2EE blueprint pattern classification feature.
The architecture design is the skeleton, and the design mode is the meat
In this way, a rich design scheme can be further completed by the programmer, carrying assistance with appropriate engineering methods, so that the project architecture design can be completed correctly and quickly.
Keep in mind the architectural design goals
Because the architecture design is completed dynamically, it is very important to grasp the objectives of the architecture design. Therefore, during the entire project process, even the overall goal of our architecture design must be kept in mind in each step. The following points can be summarized:
1. maximize reuse: This reuse includes multiple aspects, such as Component Reuse and design mode usage.
For example, we have user registration and user permission system verification in our project, which is actually a general topic. Each project only has its content and some minor differences, if we have successful R & D experience in this area, we can directly reuse it. If not, we need to develop this subitem. During the R & D process, we cannot only see the needs of this project, it is also necessary to complete this sub-project, which can be called a component, with the concept of architecture.
2. Try to be as simple as possible: the General Direction for solving the problem is to simplify the complicated problem. In fact, this is also the fundamental goal of middleware or multi-layer system technology. However, in the specific implementation of the design process, we may complicate the simple problem, especially in the use of the design model, it is easy to fan this error, therefore, it is not easy to make the design as simple and clear as possible.
I think that the implementation of each class must truly reflect the essential features of system things, because there is only one essential feature of things, and the closer your code is to it, it indicates that your design is simple and clear, and the simpler the system is, the more reliable your system is. In more cases, a class does not reflect the nature of things and requires the combination and coordination of multiple classes. Therefore, correct use of proper design patterns is a top priority.
When we look at a system code with a good architecture design, we basically see the design pattern. This is an example of pet store. You can also say that a good architecture design is basically completed by a simple and clear multiple design patterns.
3. Most flexible Scalability: the architecture design must be flexible and scalable, so that users can perform secondary development or more specific development on your architecture.
To be flexible and scalable, we need to design the architecture at the theoretical level. For example, the concept of workflow is gradually becoming popular, because the shadows of workflows exist in many practical projects, the workflow has a tree structure permission setting concept, which is more common in many fields.
The tree structure is the basic form of organizational information. The website or ERP front-end is organized by the tree menu, so when we design the architecture, the tree structure and functions can be designed separately. The links between them can be linked together through nodes in the tree structure, just as we can mount various small gifts on the branches of the Christmas tree, these small gifts are all the functions we need to implement.
With this concept, it is usually difficult to implement user-level permission control. The idea is also to link specific users or groups with nodes in the tree structure, in this way, the user's permission control on the corresponding functions is indirectly realized, and the architecture with such basic design scheme is undoubtedly flexible and scalable.
How to Design the architecture? Source: Author: 0 comments by netizens 26 times
Part 1 Layer
The concept of layer is very difficult in the computer field. The computer itself embodies the concept of a layer: the system call layer, the device driver layer, the operating system layer, and the CPU instruction set. Each layer is responsible for its own responsibilities. The Network is also a layer concept, the most famous TCP/IP layer-7 protocol.
It is also easy to use in the software field. Why? Let's take a look at the advantages of the layer-based technology:
● You use a layer, but you do not need to understand the implementation details of the layer.
● You can use another technology to change the underlying layer without affecting the applications of the above layer.
● Reduces dependencies between different layers.
● Easy to develop exit layer standards.
● The bottom layer can be used to create multiple services on the top layer.
Of course, the layer also has vulnerabilities:
● The layer cannot encapsulate all functions. Once a function change occurs, all layers are bound to be affected.
● Reduced efficiency.
Of course, the most difficult problem at the layer is what each layer has and what responsibilities it has to bear.
Typical three-tier structure
The three-tier structure is probably quite familiar to everyone. Is the presentation layer, domain layer, and infrastructure layer.
The presentation layer logic mainly processes the interaction between users and software. Currently, wimp and HTML-based interfaces are the most popular. The main responsibilities of the presentation layer are to provide users with information and translate users' instructions. To the business layer and infrastructure layer.
The logic at the infrastructure layer includes communication between processing and other systems, representing the execution of tasks by the system. For example, database system interaction and interaction with other application systems. For most information systems, the greatest logic at this layer is to store persistent data.
Another is the domain-layer logic, which is also called the business logic. It includes the calculation of input and storage data. Verify the data from the presentation layer and assign an infrastructure layer logic according to the instructions of the presentation layer.
In domain logic, people are always confused about what is domain logic and what is other logic. For example, there is a logic in a sales system: if the sales volume increases by 10% this month from the previous month, it will be marked in red. To implement this function, you may put the logic in the presentation layer and compare the numbers for two months. If the number exceeds 10%, it will be marked as red.
In this way, you put the domain logic in the presentation layer. To separate these two layers, you should now provide a method in the domain layer to compare the growth of sales numbers. This method compares the numbers of two months and returns the boolean type. The presentation layer simply calls this method. If true is returned, it is marked in red.
Example
The layer technology does not have any permanent skills. How to use it depends on the specific situation. The following three examples are provided:
Example 1: an e-commerce system. It is required to be able to process a large number of user requests at the same time. The user scope is global, and the number is still growing. However, the domain logic is simple. It is nothing more than the order processing and the connection to the inventory system. This requires us 1. The presentation layer should be friendly and can adapt to the widest range of users, so we adopt the HTML technology; 2. Support distributed processing for thousands of accesses at the same time; 3. Consider future upgrades.
Example 2: A leasing system. The system has fewer users, but the domain logic is very complicated. This requires us to create a system with extremely complex domain logic, and provide a convenient input interface for their users. In this way, wimp is a good choice.
Example 3: a simple system. Very simple, with few users and few logic. But there is no problem. It simply means fast delivery and future upgrades should be fully considered. Because the demand is constantly increasing.
When to Layer
Such three examples require that we cannot solve the problem in an overall manner, but should formulate specific solutions based on the specific circumstances of the problem. These three examples are typical.
In the second example, you may need to strictly divide it into three layers and add another mediating layer. Example 3 is not required. If you only want to view data, you only need several server pages to place all the logic.
I usually separate the presentation layer from the domain layer/infrastructure layer. Unless the Domain Layer/infrastructure layer is very simple, and I can use tools to easily bind these layers. The best example of this two-layer architecture is that in the VB and Pb environments, it is easy to build a Windows interface system based on SQL database. This presentation layer is very consistent with the infrastructure layer, but once verification and computing become complex, this method has inherent defects.
Most of the time, the domain layer and the infrastructure layer look very similar. At this time, they can actually be put together. However, when the business logic at the domain layer is different from that at the infrastructure layer, you need to separate them.
More layer Modes
The three-tier architecture is the most common, especially for is systems. Other architectures also exist, but they are not suitable for any situation.
The first is brown model [Brown et al]. It has five layers: presentation layer (presentation), control/mediation layer (Controller/mediator), Domain Layer (domain), data mapping layer (data mapping ), and data source ). In fact, it adds two intermediate layers in the three-tier architecture. The control/mediation layer is located between the presentation layer and the domain layer, and the data ing layer is located between the domain layer and the infrastructure layer.
The presentation layer and the mediation layer of the domain layer, which are commonly called the representation-domain mediation layer, are a common layered method, usually for some non-visual controls. For example, organize the information format for a specific presentation layer, navigate between different windows, process the transaction boundary, and provide the server facade interface (for the specific implementation principle, see the design mode ). The biggest danger is that some domain logic is put into this layer, affecting other presentation layers.
I often find it advantageous to allocate behavior to the presentation layer. This simplifies the problem. However, the presentation layer model is complicated. Therefore, it is worthwhile to put these behaviors into non-visualized objects and extract a representation-domain intermediary layer.
Brown Isa
Presentation Layer
Control/mediation layer representation-domain mediation Layer
Domain Layer
Database er in database interaction mode at the data ing Layer
Data Source layer infrastructure layer
The mediation layer between the domain layer and the infrastructure layer belongs to the database mapper mode mentioned in this book and is one of the three methods for connecting the domain layer to data. And representation-domain intermediary layer at a glance, sometimes useful, but not always useful.
Another good layered architecture is the J2EE architecture. For more information, see the book "J2EE Core Model. Its hierarchy is client, presentation, business, integration, and resource ). Differences include:
J2EE Core Isa
Presentation Layer on the client
Presentation Layer running on the server
Business Layer Domain Layer
Integration layer infrastructure layer
External data for communication at the resource layer infrastructure layer
Microsoft's DNA Architecture defines three layers: presentation layer, business layer, and data access. This is similar to my architecture, however, there are still many differences in data transmission methods. In Microsoft's DNA, operations at each layer are based on the SQL query result set sent from the data storage layer. In this way, the coupling between the presentation layer and the business layer and the data storage layer is increased.
The action of the DNA record set between layers is similar to that of the data transfer object.
Part 2 Organization domain Logic
To organize layer-based systems, the first thing is how to organize domain logic. There are several ways to organize domain logic. But the most important method is the transation script and domain model. One of them is selected, and others are easy to decide. However, there is no obvious line between the two. Therefore, it is also a university question how to choose. In general, we think domain model can be used for systems with complicated domain logic.
Transation script is the processing program for user input in the presentation layer. This includes verification, computing, storage, calling other system operations, and returning data to the presentation layer. A user's action represents a program. This program can be a script, transation, or subprograms. In example 1, check that adding a book to the shopping cart and displaying the delivery status can all be a transation script.
Domain model is a model for domain nouns, such as books and shopping carts in Example 1. Testing, computing, and other processing are all put into the domain model.
Transation script is structured thinking, and domain model is OO thinking. Domain model is difficult to use. Once you get used to it, you can organize more complex logic and your thoughts will be more oo. At that time, even a small system will naturally use the domain model.
But how to choose? If the logic is complex, use domain model: If you only need to access the database, the transation script will be better. However, the demand is constantly evolving, and it is difficult for you to ensure that future requirements will be so simple. If your team is not good at using the domain model, you need to weigh the input-output ratio. In addition, even the transation script can separate the logic from the infrastructure. You can use gateway.
For example 2, domain model is undoubtedly used. You need to weigh the value of instance 1. For example 3, it is hard to say whether it will be like example 2 in the future. You can use transation script now, but you may need to use domain model in the future. Therefore, architecture decisions are crucial.
In addition to the two models, there are other moderate models. Use Case Controller is between the two. Only the business logic related to a single use case is put into the object. Therefore, they are still using the transation script, while the domain model is only a set of database gateways. I don't quite use this mode.
Table module is another moderate mode. Many GUI environments rely on the returned results of SQL queries. You can create objects in the memory to split the GUI from the database. Write a module for each table. Therefore, each row requires a keyword variable to identify each instance.
The table module is suitable for scenarios where many components are built on a general relational database and the domain logic is not complex. Microsoft COM and Its. NET environment with ADO. NET are suitable for this mode. For Java, it is not applicable.
One problem with domain logic is that domain objects are very bloated. Because the object has too many behaviors, the class is too large. It must be a superset. In this case, we need to consider which behaviors are generic and which are not. They can be processed by other classes, either Use Case Controller or presentation layer.
Another problem is replication. It will lead to complexity and inconsistency. This is more dangerous than being bloated. Therefore, we would rather be bloated than copying. Wait until the system is bloated and try again.
Select a region to run the domain Logic
Our focus is on the logic layer. The domain logic either runs on the client or the server.
The simple method is to concentrate on the server. In this way, you need to use the HTML front-end and web server. The advantage of doing so is that the upgrade and maintenance are very simple. You do not need to consider the synchronization between the desktop platform and the server, or the compatibility of other software on the desktop platform.
Running on the client is suitable for situations where fast response is required and no network connection is available. In the server logic, a user's small request also needs information to be circled from the client to the server. The response speed must be slow. Besides, the network coverage does not mean that it reaches 100%.
What about each layer?
Infrastructure layer: It is generally on the server, but sometimes it will also copy data to a suitable high-performance desktop, but this is the issue of synchronization.
Where the presentation layer runs depends on the design of the user interface. A Windows interface can only run on the client. A Web interface is run on the server. There are also special examples of running Web server on a desktop, such as X server. However, this situation is rare.
In example 1, there are no more options, but only on the server side. Therefore, every bit of yours will go around a large circle. To improve efficiency, try to use some pure HTML scripts.
The main reason for choosing a Windows interface is to execute complicated tasks and a suitable application, while web GUI is not competent. This is the practice of Example 2. However, people should gradually adapt to the Web GUI, and the Web GUI functions will become more and more powerful.
The rest is the domain logic. You can either put all the servers, or all the clients, or both sides.
If it is on the client side, you can consider putting all the logic on the client side, so that at least all the logic is in one place. However, moving the Web server to the client can solve the problem of no network connection, but it will not be of much help to the response time. You can still separate the logic from the presentation layer. Of course, you need additional upgrade and maintenance work.
Logic on both the client and server is not a good solution. However, it is applicable to situations where only some domain logic is available. There is a trick to encapsulate the logic that is unrelated to the rest of the system.
Domain logic interface
Your server has some domain logic and needs to communicate with the client. What interfaces should you have? Either an HTTP interface or an OO interface.
The HTTP interface is applicable to Web browser, that is, you need to select an HTML presentation layer. The latest new technology is Web Service, which communicates through HTTP, especially XML. XML has several advantages: a large amount of communication, a good structure, and only one loop. This reduces the overhead of remote calls. XML is also a standard that supports heterogeneous platforms. XML is text-based and can be passed through the firewall.
Although XML has so many advantages, an OO interface still has its value. The hhtp interface is not obvious and it is difficult to see how the data is processed. The method of the OO interface has variables and names, so it is easy to see the process of processing. Of course, it cannot pass through the firewall, but it can provide control such as security and transactions.
The best thing is to take the strengths of both. The oo interface is down, and the HTTP interface is on. However, this will make the implementation mechanism very complicated.
Part 3 organize Web Server
Many people who use HTML cannot really understand the advantages of this method. We have a variety of useful tools, but it is difficult to maintain the program.
There are two ways to organize programs on the Web server: script and Server Page.
A script is a program that uses functions and methods to process HTTP calls. For example, CGI scripts and Java Servlets. It is no different from a common program. It obtains HTML string data from the web page, and sometimes requires expression matching. This is why Perl can become a common language for CGI scripts. While Java servelet leaves this analysis to the programmer, but it allows the programmer to access information through the keyword interface, so that there will be less expressions to judge. The Web server output in this format is another type of HTML string, called response, which can be operated through streaming data.
Worse, streaming data is very troublesome, which leads to the generation of server pages, such as PHP, ASP, and JSP.
The server PAGE method is suitable for handling simple responses. For example, "show the details of a song", but your decision-making depends on the input, it will be messy. For example, "the display format of pop and rock is different ".
Server Page is good at processing user interaction, while Server Page is good at processing formatted response information. Therefore, it is natural that scripts are used to process request interaction and server pages are used to process response formatting. This is actually the processing of View/controller in the famous MVC (Model View Controller) mode.
Web Server MVC Workflow
The first point of applying the Model View Controller mode is that the model must be completely isolated from the web service. Use the transaction script or domain model mode to encapsulate the processing process.
Next, we will classify the remaining modes into two types: the controller mode and the view mode.
View Mode
There are three view modes: Transform view, template view, and two step view. The processing of transform view and template view is only one step. domain data is converted to HTML. Two Step view requires two steps. The first step is to convert domain data into a logical representation, and the second step is to convert the logical representation to HTML.
The advantage of two-step processing is that the logic can be centralized in one place. If there is only one step, you need to modify each screen when the change occurs. But you need to have a good logical screen structure. If a web application has many front-end users, the two-step processing is particularly useful. For example, the airline ticket booking system. Different logic screens can be obtained through step 2 processing.
The single-step method has two optional modes: Template view and transform view. At the time of template view, code is embedded into HTML pages, just like the current server page technology, such as ASP, PHP, and JSP. This mode is flexible, powerful, but disorganized. If you can organize the logic program logic well outside the page structure, this mode still has its advantages.
Transform view uses the translation method. For example, XSLT. If your domain data is processed in XML, this mode is particularly useful.
Controller mode
Controller has two modes. Generally, we decide a control based on the action. An action may be a button or link. This mode is the action controller mode.
The Front Controller further separates the processing and processing logic of HTTP requests. Generally, only one web handle is used to process all requests. All your HTTP requests are handled by one object. The impact of changing the action structure will be minimized.