This is the sixth day of my participation in the August More text Challenge. For details, see:August is more challenging

Sequence diagrams show how objects collaborate in terms of time series. It shows how objects interact with other objects in a particular scenario of a use case.

The element

UML sequence diagrams invariably begin with sequenceDiagram in the Markdown syntax.

Participant/role

  • Participants/Actors can be declared implicitly or explicitly in the same order as they are declared in the code.
  • Implicitly declared
Boss ->> Xiao Ming: Hello Xiao Ming ->> Boss: Hello Boss -) Xiao Ming: Please go outCopy the code
Xiao Ming: Hello xiao Ming -->> Boss: Hello Boss -) Xiao Ming: Please go out
  • The explicit declaration
Xiao Ming boss ->> Xiao Ming: Hello Xiao Ming -->> Boss: Hello boss -) Xiao Ming: please get outCopy the code
Xiao Ming boss ->> Xiao Ming: Hello Xiao Ming -->> Boss: Hello Boss -) Xiao Ming: please go out

The alias

  • We can give the participants a convenient alias and then just use the alias after that.
participant B asThe boss the participant MasXiao Ming B->>M: Hello M- >>B: Hello B-)M: Please go outCopy the code
M as Xiaoming B->>M: Hello M- >>B: Hello B-)M: Please go out

The message

  • Message lines can be represented by solid and dashed lines.
type describe
-> A solid line without an arrow
–> There is no dotted line with arrows
->> A solid line with an arrow
–>> Dotted lines with arrows
-x A solid line with a cross at the end
–x A dotted line with a cross at the end
-) Solid line with open arrow
-) Dotted line with open arrow
participant B asThe boss the participant MasXiao Ming B - > M: how are you B - > M: hello - > B > M: hello - > B > M: hello - > B > M: how are you B - x M: hello - x M B: hi B -) M: hello M -) B: gnuCopy the code
M as Xiaoming B -> M: Hello B -> M: Hello B ->> M: Hello B ->> M: Hello B ->> M: Hello B ->> M: Hello B -x M: Hello B -x M: Hello B -) M: Hello M -) B:gun

The activation

  • Activate or deactivate a role.
  • Implement using activate/deactivate
participant B asThe boss the participant MasB -> M: Hello B -> M: Hello B -) M: Hello M --) B: Gun deactivate MCopy the code
B -> M as Participant B -> M as Participant B -> M Hello B -) M: Hello M --) B: Gun Deactivate M
  • Use +/- after the message arrow
participant B asThe boss the participant MasB -> M: Hello B -> M: Hello B -) M: Hello M --) B: Gun deactivate MCopy the code
M as Xiaoming B-> M: Hello B-> + M: hello B-) M: hello M --) -B :gun
  • The same role is activated repeatedly
participant B asThe boss the participant MasXiao Ming - > B + M: hello -) B + M: hello M -- -- > B: hello M -) - B: gnuCopy the code
SequenceDiagram B as boss Participant M as Xiaoming B ->+ M: Hello B -)+ M: hello M -> -B: hello M --) -B :gun

instructions

  • Add a description to the sequence diagram. You can customize the location of the description by specifying directions
  • Left of, right of, over
participant B asThe boss Note leftofB: See youasXiao Ming Note rightofM: The chairman's own grandson Note over B,M: loving family - > B + M: hello -) B + M: hello M -- -- > B: hello M -) - B: gnuCopy the code
Note over B,M: Loving family - > B + M: hello -) B + M: hello M -- -- > B: hello M -) - B: gnu

cycle

  • Represents a loop
participant B asThe boss Note leftofB: See youasXiao Ming Note rightofM: The chairman's own grandson B ->> M: Hello M -) B: My grandfather is the chairman of the boardCopy the code
B ->> M as participant B ->> M M -) B: My grandpa is the chairman of the board. This is a loop

That’s an introduction to UML timing diagrams and the associated Markdown syntax.