The design principles of architecture should also be the guiding principles of software system design.
First case
This is the most well-known situation. The client sends a request to the N layer, and the N layer cannot complete the request independently. To call the service provided by the N-1 layer, the N-1 layer also needs its subordinates, that is, the service provided by the N-2 layer. Until the second and second layers.
The 1st layer can complete its own tasks independently and return the execution results to the 2nd layer. After the result of Layer 3 is obtained at Layer 3, you can continue to complete your task. It will continue to push the execution result up, that is, transfer the result at Layer 2nd. Until the N-1 layer and N layer.
Figure 12. In an architecture with N layers, requests are passed down from top to bottom and results are passed down from bottom to top. |
The system's client only knows layer n. It sends a request to layer N and receives the result from layer n. The client does not know the existence of other layers. See.
Figure 13. The client only knows layer N, but does not know other layers. |
Case 2
This second case represents the communication from bottom to top, which is called notification ). This series of actions started at Layer 1st, which, after being processed, passes the notification up to layer 2nd and continues up to layer 3rd until the N-1 and N layers. See.
Figure 14. In an architecture with N layers, notification is transmitted from bottom to top. |
Readers who have used USB devices know that once a USB device is inserted into a computer, the USB driver immediately discovers that the device is activated and notifies the device of the software, the device operation software starts. This series of behavior is the process of passing the notification from bottom to top.
In the first case, the request first passes down, and then the result is reversely transmitted to form a ring. In the second case, notification transmission is unidirectional.
Case 3
This is similar to the first case, but only involves some layers.
First, the client sends a request to the N layer, and the N layer cannot complete the request independently, you need to call the services provided by the N-1 layer, the N-1 layer also needs his subordinates, that is, the service provided by the N-2 layer. Until layer J.
The J-level can independently complete its own tasks without the need for a J-1 layer. It returns the execution result to layer J + 1. After the result of the J + 1 layer is obtained, you can continue to complete your own task. It will continue the execution result, that is, transfer the result of the J + 2 layer. Until the N-1 layer and N layer. See.
Figure 15. In an architecture with N layers, the request is passed up to a certain intermediate level and the result is passed down from there. |
Similarly, the client only knows layer N, but does not know the existence of other layers.
Case 4
This situation describes the process of notification bottom-up transfer, but the second case involves all N layers, and here it only involves some layers. See.
Figure 16. The communication process is unidirectional when the notification is passed up to an intermediate layer from layer 1st. |
First, all the actions start at Layer 1st. After processing, the notification is forwarded to layer 2nd and forwarded to layer 3rd until Layer J, it will not be passed up.
Case 5
This situation involves two hierarchies, which communicate with each other, often referred to as protocol stacks ). In the following figure, the N layer on the left sends a request, which is passed down, through the N-1 layer ,... Layer 3 until Layer 3.
At this time, the request is then passed to layer 1st on the right, and then passed up the hierarchy, through layer 2nd, layer 3rd, etc. until the N-1 layer and layer n.
Figure 17. Requests are passed down from layer N on the left to layer 1st and then to the right. |
The execution result is passed to the opposite from the N-layer on the right, through the N-1 layer on the right, the N-2 layer ,... Layer 3 and Layer 3 are returned to the Layer 3 on the left, and then passed up along the hierarchy on the left, passing through Layer 3, Layer 3 ,... To the N-1 layer, return to the N layer.
Figure 18. The result is passed down from layer N on the right to layer 1st and then to the left. |
Clients A and B at both ends only know their n-th layer, but do not know other layers. They will think that there is a connection between the two layers. In fact, this connection is virtual, is performed through other layers.
Figure 19 Client A sends a request to layer N on the left. After the intermediate process, it reaches layer N on the right and then passes the request to the customer on the right. |
TCP/IP hierarchy
The TCP/IP design follows the hierarchical principle. For details, see.
Figure 20. TCP/IP design diagram. |
Non-circular dependency principle (ADP)
Cyclic dependency is not allowed in hierarchical dependencies. For example, the figure below shows the dependency from layer n to the N-1 layer, from the N-1 layer to the J layer, from the J layer to the 2nd layer, there is no problem with the dependency from layer 2nd to layer 1st. However, there is also a dependency between layer J and layer n. This leads to a circular dependency, which should be avoided.
Figure 21 shows a circular dependency. |
Each layer is represented by a wooden board, which is placed on one layer. The upper-layer boards depend on the lower-layer boards. This is the dependency relationship. Such dependency is not circular, because Euclidean ry is not allowed. If we have to design a circular dependency, we have to forge the geometry. For more information, see.
Figure 22. Impossible ry: This geometric structure cannot be implemented in three-dimensional Euclidean space. |