How to draw multiple returns in UML sequence diagram

aleung picture aleung · Jun 12, 2012 · Viewed 8k times · Source

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

In below example, return line 'a' ends methodX(), how to draw return line 'b'?

String methodX(int i) {
  if (i>0)
    return 'a';
  else
    return 'b';
}

     +------------+            +------------+
     |    Foo     |            |     Bar    |
     +-----+------+            +------+-----+
           |                          |
           |        methodX(i)         |
          +-+----------------------->+-+
          | |                        | |
  +-----+------------------------------------+
  | alt | | |  [i>0]                 | |     |
  +-----+ | |           a            | |     |
  |       | |<- - - - - - - - - - - -+-+     |
  |       | |                         |      |
  |       | |                         |      |
  +------------------------------------------+
  |       | |  [else]                 |      |
  |       | |                         |      |
  |       | |           b             |      |
  |       | |<- - - - - - - - - - - - | ??   |
  |       | |                         |      |
  |       | |                         |      |
  +------------------------------------------+
          | |                         |
          +-+                         |
           +                          +

Answer

vainolo picture vainolo · Jun 13, 2012

The problem is with your tool, not with UML. Check out visual paradigm for UML. You can manually add activations at the start of each alt fragment and at the end of the activation send the return message.