Software project management [UML-sequence diagram]

1. What is a timing diagram?

Sequence diagram is an object behavior modeling based on interaction. It is a method used by UML to describe the interaction process of information between objects. It is a model that describes the collaborative relationship between objects.

Sequence diagram is more of a name. What we usually call sequence diagram and sequence diagram are also called it.

Sequence diagrams are used to capture the time-sequential interactions between objects in the running system and are composed of lifelines and messages.

Sequence diagrams represent interactions as a two-dimensional diagram. The vertical axis is the time axis, and time extends downward along the vertical line. The horizontal axis represents the classifier role of each individual object in the collaboration. Classified roles are represented by lifelines. When the object exists, the role is represented by a dashed line, and when the object's process is active, a rectangular box is added to the lifeline. Messages are represented by arrows from the lifeline of one object to the lifeline of another object. Arrows are arranged in chronological order from top to bottom in the diagram.

2. Composition elements

1. Role

This role can be a user, external system, machine, etc.

Represented by a little person

2. Objects and lifelines

Object: An instance of a class. Of course, in a sequence diagram, it can be a class or an object of the class.

Regarding the naming of objects:

  1. Object name and class name , for example: dispatcherServlet:DispatcherServlet
  2. Only the class name is displayed , which means it is an anonymous object, for example: :DispatcherServlet
  3. Only the object name is displayed without the class name , for example: dispatcherServlet

Lifeline: Represented in a sequence diagram as a dotted line extending downward from the object icon, indicating the time the object exists.

3. Activity bar (activation bar)

An activity bar can be used on the dotted line of the lifeline to represent the beginning and end of a certain behavior (function), usually represented by a small rectangle.

4. Message (interactive behavior)

What is a message?

In object-oriented analysis and design, the behavior of objects is also called messages, because the interaction of behaviors between objects can also be seen as sending messages between objects . Typically, a message is passed when one object invokes behavior in another object.

Sequence diagrams focus on the communication between lifelines, which are messages sent by objects. UML represents messages with solid arrows between lifelines, with each message pointing from the sending object to the receiving object.

Classification of messages

  • Simple message: It indicates how control is sent from one object to another object, and does not contain the details of the control.
  • Synchronous messages: means blocking and waiting. For example: after A sends a message to B, object A must wait until B returns after completion of execution before it can continue execution. This is the sync message. (Synchronization messages need to establish a synchronization channel, which is initiated by the initiator, waits for confirmation by the receiver, starts the interaction after confirmation, and disconnects the channel after the interaction is completed)
  • Asynchronous messages: means non-blocking. For example: after A sends a message to B, the following code can be executed directly without waiting for B's execution.

representation of message

Synchronous messages are represented by solid arrows, and asynchronous messages are represented by open arrows.

self call message

Message return value:

3. Interaction box

UML added interactive boxes to sequence diagrams in 2.0. The interaction box is used to address the conditions and manner of interactive execution. It allows the direct representation of logical components in sequence diagrams and is used to define special conditions and sub-processes for any part of any lifeline by specifying the application area of ​​​​the condition or sub-process.

type parameter meaning
ref none Represents the interaction defined in another diagram. A large graph can be divided into several smaller graphs to facilitate graph management and reuse.
assert none Represents the only valid execution path for interactions that occur within the interaction box. It helps indicate when each step of the interaction must be successfully executed. It is often used with state variables to enhance a certain state of the system.
loop min times,max times,[guard_condition] Loop fragment that executes the loop when the condition is true. It can also be written as loop(n) to represent looping n times, which is similar to the for loop in Java or C#.
break none If the interaction contains a break, then any behavior enclosed in the interaction must be pushed out, especially the loop segment, which is similar to the break statement in Java.
alt [guard_condition1]...
[guard_condition2]...
[else]
Select fragments to express mutually exclusive conditional logic in the realm, similar to if...else... statements.
neg none An invalid interaction was demonstrated.
opt [guard_condition] Optional fragment, executed when the alert value is true.
par none Parallel fragments express parallel execution.
region none Region, indicating that only one thread can run in the region.

alt (select fragment)

To put it simply, if/else is expressed in the diagram

opt

Contains a sequence that may or may not occur;

As long as my score is less than 60, my mother will definitely hit me.

If it's greater than that, it won't happen.

Loop

The segment is repeated a certain number of times, and the conditions for segment repetition can be indicated in the critical

Par (parallel)

4. Examples

Guess you like

Origin blog.csdn.net/weixin_62421736/article/details/133300746