Dynamic modeling mechanism of standard modeling language UML

zhaozj2021-02-08  439

Dynamic modeling mechanism of standard modeling language UML

(This article is reproduced from Software Engineering Expert Network www.21cmm.com)

Message

In object-oriented techniques, the interaction between objects is done by the transmission of inter-object messages. This concept is used in the four dynamic models of UML. Typically, a message delivery is completed when an object calls an operation in another object. When the operation is executed, the control returns to the caller. Objects cooperate with each other, and constantly changing its own state based on the results of communication in their life cycle. In UML, the graphical representation of the message is associated with the sender of the message with the arrow, and the type of arrow indicates the type of message, as shown in FIG.

There are three messages defined by the UML: Simple Message indicates a simple control stream. Used to describe how to pass during the object without considering the details of communication. Synchronous Message represents the nested control flow. The call is a typical synchronization message. After the caller issued a message, you must wait for the message to return, and only the caller can continue to perform its own operation only if the operation of the processing message is executed. Asynchronous Message represents an asynchronous control flow. You can continue to perform your own operation without waiting for the message to return to the message. Asynchronous messages are mainly used to describe and release in real-time systems.

2. Status diagram

State diagram is used to describe all possible states of a particular object and events thereof caused by state transitions. Most object-oriented technologies use state diagrams to represent a single object in its life cycle. A state diagram includes a series of states and a shift between states. (1) All objects have a state in which the status is the result of a series of activities. When an event occurs, the status of the object will change. The state defined in the state diagram is: initiality, final state, intermediate state, composite state. Among them, the initiality is the starting point of the state map, and the final state is the end point of the status diagram. A state diagram can only have an initial state, and the final state can have multiple. The intermediate state includes two areas: name fields and internal transfer domains, as shown in Figure 3. The internal transfer domain in the figure is optional, where the listed operation will be performed when the object is in this state, and the operation of the action does not change the state of the object.

One state can be further refined into a plurality of sub-states, and we will be able to further refine the state called a composite state. There are two relationships between "or relationships" and "relationships" between sub-states. Or relationship (Figure 4) illustrates only one sub-state at a certain moment. For example, a car in a driving state, in the composite state of "travel", two different sub-states in the back, and the car is either forward at a moment, or later. With the relationship (as shown in Figure 5), a plurality of sub-states (referred to as a concatenatic state) can be reached at the same time in a composite state. A state diagram having a concurrent sub-state is called a concurrent state diagram.

(2) The connection between the arrow between the state of the transfer state is called the transfer. The state of change is usually triggered by an event, and the event expression of the trigger transfer should be marked on the transfer. If the event is not indicated on the transfer, it means that the transfer is automatically triggered after the internal activity of the source state is completed.

3. Sequence diagram

The sequence diagram is used to describe the dynamic interaction between the objects, focusing on the time order of the inter-object messaging. There are two axes in the sequence diagram: the horizontal axis represents different objects, and the vertical axis represents time. The object in the sequence diagram is represented by a rectangular frame with a vertical dashed line, and is marked with an object name and class name. Vertical dashed lines are the lifeline of the object, which is used to indicate that the object is present within a certain period of time. Communication between objects is represented by drawing messages between the life of the object. The arrow of the message indicates the type of message. The message in the sequence diagram can be a signal (Signal), an operation call, or a RPC (RemoteProce Dure Calls) in C , and RMI (Remote Method Invocation) in Java. When a message is received, the receiving object immediately starts an active activity, ie the object is activated. The activation is represented by displaying an elongated rectangular frame on the object line. The message can be identified by the message name and parameters. The news can also be served, but less use. The message can also be provided with conditional expressions, indicating a branch, or deciding whether to send a message. If used to represent a branch, each branch is mutually exclusive, that is, only one message in the branch can be transmitted at a certain time. In the left side of the sequential diagram, there may be explanation information, and the timing of the message transmission, the execution of the action, and the constraint information, and the like. A typical example is to illustrate a message being repeatedly sent. In addition, the time limit between the two messages can be defined. An object can create another object by sending a message, which is identified by "X" when an object is deleted or self-deleted. In addition, in many algorithms, recursion is a very important technique. When one operation is directly or indirectly called itself, recursive occurs. Generating recursive messages always synchronize messages, and return messages should be a simple message. 4. Cooperation map

Collaboration Diagram is used to describe interaction relationships and link relationships between objects that cooperate. Although sequential diagrams and collaborators are used to describe the interaction between the objects, the side focus is different. The sequence diagram focuses on the time order of interaction, and the cooperation map focuses on the static link relationship between interactive objects. The appearance of the object in the cooperation map is the same as the sequence diagram. If an object is created in the interaction of the message, you can mark {new} after the object name. Similarly, if an object is deleted during interaction, you can labeled {design} after the object name. Link relationship between objects is similar to the contact in the class map (but there is no multi-weight flag). By marking messages with a message string (simple, asynchronous or synchronous messages) on the link between the objects (simple, asynchronous, or synchronous messages). (1) Link link to represent various relationships between objects, including constituting linkages, links for aggregation links, Limited Links, Navigation Link, Navigation Link . Various link relationships are the same as the definition in the class diagram, and the role name and template information of the object can be displayed in the link of the endpoint position. (2) The message stream is on the link line of the cooperation graph, and the interaction between the object can be described with a message with a message string. The arrow of the message indicates the flow direction of the message. The message string illustrates information such as the message, the parameters of the message to be sent, the return value of the message, and the serial number of the message.

5. Activity Diagram

The application of the activity map is very wide, which can be used to describe the behavior of the operation (class method), or the work procedure within the use case and the object. The activity map is changed by the state diagram, which are each used for different purposes. The active map captures the results of the action (the work or activity of the action) and the action of the active map according to the change of the object state. An active map will immediately enter the next activity (the change in the status in the state map may require the trigger of the event). Figure 1 shows an example of a activity diagram.

Activity and transfer one can be described as a series of related activities. There is only one starting point, but there can be multiple end points. The transfer between the event allows the same for Guard-Condition, Send-Clause, and Action-Expression, which is the same as that defined in the status diagram. An activity can be sequentially followed by another activity, which is a simple order relationship. If a rhombus is used in the active diagram, the conditional relationship can be expressed (see Figure 1), and the determination flag can have multiple input and output transfer, but only one output transfer is triggered in the active operation. The activity map is also useful to represent and distribute it. In the active diagram, use a horizontal thick line called the synchronous bar to divide a transition into a plurality of concurrent execution, or a plurality of transitions into a transfer. At this time, only the input transfer is valid, the synchronization bar triggers the transfer, and then performs the following activities, as shown in Figure 2.

The lane activity map tells you what happened, but did not tell you who the activity will be done. In programming, this means that the activity diagram does not describe which class is completed. The lane solves this problem. It combines the logical description of the activity map and the sequential diagram and cooperation graphs. As shown in FIG. 2, the lane is represented by a rectangular frame, and the activity belonging to a lane is placed in the rectangle, and the object name is placed on the top of the rectangular frame, indicating the activity in the lane, is responsible for the object. Objects can appear in the active diagram. Objects can be used as an input or output of the activity, and the input / output relationship between the object and the activity is represented by a dotted arrow. If only objects are affected by a certain activity, you can connect objects and activities with dotted lines without arrows, as shown in Figure 2.

The signal is shown in FIG. The sending and receiving flag can also be connected to an object, and the sender and the receiver used to represent the message.

6. Application of four graphs

The above is a brief introduction to the four charts (state diagrams, sequential diagrams, collaboration graphs, and activity graphs) for describing system dynamic behavior. These four figures can be used for dynamic modeling of the system, but their respective side focus is different for different purposes, respectively. The following is a simple summary of how to use these pictures correctly, and these recommendations should be used flexibly according to the specific situation during the actual modeling process. First, do not draw a state diagram for each class in the system. Although this is perfect, it is too wasteful, in fact, you may only care about some kinds of behavior. The correct approach is to draw a status map for help understand the class. The status diagram describes the behavior of a single object across multiple use cases, not suitable for the behavior cooperation between multiple objects. To this end, a state diagram is often used in combination with other techniques (such as sequential diagrams, cooperation graphs, and activity graphs). The sequence diagram and cooperation graphs are suitable for describing the behavior of several objects in a single use case. Where sequential map protrude the order of inter-object interaction, the layout method of the cooperation map can more clearly represent the static connection relationship between the objects. The sequence diagram and cooperation diagram are the best choice when behavior is simpler. However, when behavior is complicated, the two figures will lose their clarity. Therefore, if you want to display complex behavior across multiple use cases or multi-threaded, you can consider using the active diagram. In addition, the sequence diagrams and cooperation diagrams are only suitable for describing the cooperative relationship between objects, and not suitable for accurate definitions of behavior. If you want to describe the behavior of a single object across multiple use cases, a state diagram should be used.

转载请注明原文地址:https://www.9cbs.com/read-566.html

New Post(0)