How to represent an if condition1 else if contion2 on a sequence diagram?

Mauricio Pastorini picture Mauricio Pastorini · Jul 2, 2016 · Viewed 14.9k times · Source

I was wondering, how can one represent "if cond1 else if cond2" statement on a sequence diagram?

    if (condition1) {
      // Do something
    } else if(condition2)
    {
      // Do something else if
    }

Im not sure if is it with two independent "Opt" clause

If possible create an image representation of a solution.

Answer

Christophe picture Christophe · Jul 2, 2016

In the sequence diagram, you can use a combined fragment with an alt operator. This allows you to show alternative behaviors:

  • Graphically, the alternatives are in tiled regions separated by dashed horizotal lines.
  • You can document the precise condition for each alternative in a guard (i.e. [condition]).

Example:
enter image description here

Additional reading: