How to draw multiple returns in a UML sequence diagram

In a UML sequence diagram, a method can have only one return line (at least in Astah I cannot draw two return lines from one method), how can I simulate multiple returns in if-else blocks?

In the example below, the returned string 'a' completes the X () method, how to draw the return line of 'b'?

String methodX(int i) { if (i>0) return 'a'; else return 'b'; } +------------+ +------------+ | Foo | | Bar | +-----+------+ +------+-----+ | | | methodX(i) | +-+----------------------->+-+ | | | | +-----+------------------------------------+ | alt | | | [i>0] | | | +-----+ | | a | | | | | |<- - - - - - - - - - - -+-+ | | | | | | | | | | | +------------------------------------------+ | | | [else] | | | | | | | | | | b | | | | |<- - - - - - - - - - - - | ?? | | | | | | | | | | | +------------------------------------------+ | | | +-+ | + + 
+4
source share
2 answers

The problem is with your tool, not with UML. Check out the visual paradigm for UML . You can manually activate activation at the beginning of each fragment of alt and send a response message at the end of activation.

+1
source

Quick Observations:

(1) Remember that a class / object can send messages to itself (“DoSomething”), this makes “alternatives” more difficult to prevent.

(2) When using "alt", you must specify the conditions. "alt" represents "if-then-else", "switch-case" and similar concepts from programming languages.

And these sentences have conditions that must be added to the UML diagrams ("[condition]").

(3) Within each condition or case of "alt" there can be several messages among several objects, either for oneself or not (only the arrow "return").

 .......................................................... .......+---------+..............+---------+............... .......| Foo |..............| Bar |............... .......+----+----+..............+----+----+............... ............|........................|.................... ..........+-+-+....................+-+-+.................. ..........| |......methodX().....| |.................. ..........| +------------------->+ |.................. ..........| |....................| |..DoSomething()... ..........| |....................| +---+.............. ..........| |....................| |...|.............. ..........| |....................| |...|.............. ..........| |....................| |...|.............. ..........| |....................| |<--+.............. ..........| |....................| |.................. ..+-----+-------------------------------------+........... ..|.alt.|.| |....................| |......|........... ..+-----+-------------------------------------+........... ..|.[option=1].....................| |......|........... ..|.......| |....................| |......|........... ..|.......| |....................| +---+..|........... ..|.......| |....................| |...|..|........... ..|.......| |....................| |...|..|........... ..|.......| |....................| |...|..|........... ..|.......| |....................| |<--+..|........... ..|.......| |<-------------------+ |......|........... ..|.......| |....................| |......|........... ..+-----+-------------------------------------+........... ..|.[option=2].....................| |......|........... ..|.......| |....................| |......|........... ..|.......| |....................| |......|..// The wide bar its kept, ..|.......| |<-------------------+ |......|..// even if there is a ..|.......| |....................| |......|..// previous return arrow ..+-------------------------------------------+........... ..|.[else]|...|....................| |......|........... ..|.......| |....................| |......|........... ..|.......| |....................| |......|........... ..|.......| |<-------------------+ |......|........... ..|.......| |....................| |......|........... ..+-------------------------------------------+........... ..........| |....................| |.................. ..........+-+-+....................+-+-+.................. ............|........................|.................... ............|........................|.................... ............X........................X.................... .......................................................... 

Greetings.

PD Any Cheeseburger or Catfish Tuna Fisherman?

+1
source

All Articles