The interaction diagram is used to describe how objects interact in the system, that is, how a group of objects transmit messages.
An interaction diagram consists of a group of objects and their relationships, including: What objects are required, what messages are sent between objects, what roles start a message, and how messages are sent in what order.
Interaction graph classification:
Interaction graphs are divided into two types: sequence graphs and collaborative graphs.
- Sequence Chart-emphasize the Event Sequence of messages
- Collaboration diagram-emphasizing the interaction between objects
The sequence diagram describes the time sequence of passing messages between objects. It is used to indicate the behavior sequence in the use case.
Sequence diagram, including chronological order, excluding object contact. That is to say, in a sequence chart, we only need to consider the sequence of system behaviors, rather than the relationship between them. You can draw actions between objects in chronological order.
In UML, a two-dimensional diagram describes the interaction between objects in the system. The vertical axis indicates the time, and the horizontal axis indicates the objects involved in the interaction.
Composition of the sequence chart:
- -Object and role: rectangular box above. In the interaction diagram, the objects involved in interaction can be both specific and prototype objects. As a specific thing, an object represents something in the real world.
- Lifeline and control focus: each object has its own lifeline. The object lifeline is a vertical dotted line to indicate that an object exists for a period of time.
- Message: communication between objects, which can be signals or operation calls.
Among them, messages are mainly in the following forms:
- Call: an operation that calls an object. It can be a call between objects, or call the object itself.
- Return indicates that the called object returns a value to the caller.
- Send: an object sends signals. Different from a call, a call is a synchronous mechanism, while a signal is an asynchronous mechanism. That is to say, when object a calls object B, after a sends the message, it will wait until B executes the called method; if object a sends a signal to object B, object a continues to run after the signal is sent.
- -Creat indicates the beginning of the object lifeline,
- The destroy (destory) is usually connected with the life termination symbol of the target object.
Message Representation Method: It is represented by a message line. messages from one object to another are represented by a message line spanning the object lifeline, including reverse messages.
Message category:
Synchronization: to a certain extent, it can be regarded as a single thread. After the thread requests a method, it waits for the method to reply to it; otherwise, it will not execute it.
Asynchronous: to a certain extent, it can be seen as a multi-thread. After a method is requested, the other methods are executed.
PS: Generally, you can use a simple message.
Collaboration diagram: emphasize the organizations that participate in interaction objects.
Relationship between a collaboration diagram and a sequence diagram:
- The two are semantically equivalent.
- The two can convert each other
- The two have different focuses:
- Sequence diagram emphasizes chronological order
- A collaboration diagram focuses on the relationship between objects.