Communication diagram and sequence diagram represent the same interactions from a different angle. But the simplified graphical representation of the messages implies restrictions in the communication diagram when it comes to combined fragments.
In the communication diagram you can represent:
- simple sequence of messages and nested messages, via the chronological numbering, e.g.:
1
,2
,3
and decimal numbering, e.g. 2.1
, 2.2
, 2.2.1
- loops (
loop
operator in sequence diagram), using a *
following the number. More specific looping specifications could follow the start between brackets e.g. *[1..n]
or *[element in collection]
. Your loop conditions are unspecified in the sequence diagram, so a *
would do.
- simple conditions (
opt
operator in sequence diagram), using a condition between brackets after the number e.g.[t>10]
In your example, we could therefore imagine: `
1: Enters username and passord
2: Check validity
2.1*: Mismatch of name or password // return message, not usual
2.2: Prompt user to re-enter credentials
2.3: Re-enter username and password
2.4: Re-check validity // missing in the SD in the loop
3: Verify user
4: USer verified
5: Display profile
Now there are two issues here: first, in your sequence diagram, there is a missing check validity
in the loop. Second, I showed for simplicity all the messages, but in a communication diagram you would usually not sho return messages, to keep things simpler. So we'd have a slightly simpler model:
1: Enters username and passord
2: Check validity //message, return is implicit
3.1*[credentials invalid]: Prompt user to re-enter credentials
3.2: Re-enter username and password
3.3: Check validity
4: Read user
5: Display profile
Advice for the choice between SD and CD:
- if you have many involved lifelines, either make several smaller SDs or opt for the CD.
- if you have many message exchanges, especially between the same lifelines, prefer SD, because following the numbers on a CD is exponentially unintuitive with the increase of messages, and long lists of messages above the arrows look ugly.
- if you have many combined fragments, or if you have more than loops and optionals, stay with SD.