Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A sequence diagram is an interaction diagram that shows how processes operate with one another and in what order.

Most developers would find the syntax fairly familiar. The following example demonstrates some basic syntaxes.

Zenuml sequence macro
uuide81b78c9-ceaf-4e5b-ab09-a87d597f857b
customContentId1712979978
updatedAt2022-10-10T08:48:13Z

The above diagram is generated from the follow text:

Code Block
// Optionally declare a participant (see Participant)
@Lambda BookLibService
// Sync message; <br>
// Use `A->B: message` for async messages
BookLibService.Borrow(id) {
  // Nested message
  User = Session.GetUser() {
    // Self message
    loadUserProfile()
  }
  // Alt fragment; also try `while`, `par` (see Fragments)
  if(User.isActive) {
    // Try/Catch/Finally fragment
    try {
      BookRepository.Update(id, onLoan, User)
      // Creation message with return message
      receipt = new Receipt(id, dueDate)
    } catch (BookNotFoundException) {
      ErrorService.onException(BookNotFoundException)
    } finally {
      Connection.close()
    }
  }
  // separte return message
  return receipt
}

Participants

The participants can be defined implicitly as in the first example on this page. The participants are rendered in order of appearance in the diagram source text. Sometimes you might want to show the participants in a different order than how they appear in the first message. It is possible to specify the participant’s order of appearance by doing the following:

Code Block
B
A
A.method()
A->B: Event
Zenuml sequence macro
uuida1abacc4-481c-4e4e-9e46-29e892a867ad
customContentId1712783365
updatedAt2022-02-04T23:12:42Z
B
A
A.method()
A->B: Event

Participant group

We can group the participants with group keyword.

Code Block
group GroupName {
  A
  B
}
C
Zenuml sequence macro
uuida0013de1-192c-4200-80e5-4ccf41046815
customContentId1711079461
updatedAt2022-01-15T22:10:01Z
group GroupName {
  A
  B
}
C

Participant type (Annotation)

We can change the shape of the participant representation with annotations.

Code Block
@Actor A
@Database B
@Boundary C
@Control D
@Entity E
@EC2 F
@ECS G
@RDS H
@S3 I
@IAM J
@Lambda K

Stereotype

It is possible to add stereotypes to participants using << and >>.

Code Block
<<Callable>> B
<<Service>> A
A.method()
A->B: Event
Zenuml sequence macro
uuid00fa2199-9f9b-4132-8a0d-2187df19f0fa
customContentId1712947203
updatedAt2022-02-04T23:13:00Z

Starter

Status
colourBlue
titleadvanced

By default, the “client” of the interaction is not shown in the diagram. However, you can specify a “client” with the @Starter keyword. Specifically, if the starter’s name is “User” or “Actor”, we will use a Stickman icon. @Starter must be put after you have declared all participants and before any messages.

Code Block
<<Callable>> B
<<Service>> A
@Starter(User)
A.method()
A->B: Event
Zenuml sequence macro
uuid100349a5-ae3c-42eb-b440-c5adab28c2df
customContentId1713176577
updatedAt2022-02-04T23:13:16Z

Messages

A message is shown as a line from the sender MessageEnd to the receiver MessageEnd.

Info

See Unified Modeling Language v2.5.1, section 17.4.4.1.

Message type

DSL

Line and arrowhead (Spec)

Async

A->B: Async message

solid line with open arrowhead

Zenuml sequence macro
uuid8cb206d5-54d6-45a5-b629-094ab2366dfb
customContentId1712947211
updatedAt2022-02-04T23:13:29Z

Sync

A.method()

filled arrowhead

Zenuml sequence macro
uuidfd447138-8a3e-4c67-8a17-93d996c28b67
customContentId1712914445
updatedAt2022-02-04T23:13:39Z

Reply

  1. ret = A.method

  2. return ret

  3. @return A->B: message

dashed line with either an open or filled arrowhead
* ZenUML renderer use open arrowhead.

Zenuml sequence macro
uuid5b1ae990-f897-4f80-ad7e-8c18c49b8efd
customContentId1713242113
updatedAt2022-02-04T23:13:53Z

Object creation

new ClassName()

dashed line with an open arrowhead

Zenuml sequence macro
uuide6ab60f3-0f31-45ba-aabe-eeeee6d9401c
customContentId1712914451
updatedAt2022-02-04T23:14:05Z

Object deletion

Status
colourRed
titleNOT SUPPORTED YET

Must end in a DestructionOccurrenceSpecification

Lost

Status
colourRed
titleNOT SUPPORTED YET

A small black circle at the arrow end of the message

Found

Status
colourRed
titleNOT SUPPORTED YET

A small black cirle at the starting end of the message

Loops

The loop operand will be repeated a number of times. This is expressed by the notation:

Code Block
while(condition) {}
for(enumerator) {}
forEach(enumerator) {}

See the example below:

Code Block
loop("Every minute") {
  Alice->Bob: Great!
}
Zenuml sequence macro
uuidb826eb57-3f43-44b0-a88d-c852034e9db7
customContentId1713078283
updatedAt2022-02-04T23:14:15Z

Alt

The alt operand represents a choice of behavior. At most one of the operands will be chosen. This is expressed by the notions:

Code Block
if (condition1) {
  ...
} else if (condition2) {
  ...
} else {
  ...
}
Code Block
if (x) {
  A.m1()
} else if (y) {
  A.m2()
} else {
  A.m3()
}
Zenuml sequence macro
uuid2e636d8c-99a7-425a-aa12-a760a8632634
customContentId1713143811
updatedAt2022-02-04T23:14:26Z