Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 360
Mauricio Pastorini Avatar asked Jul 02 '16 20:07

Mauricio Pastorini


People also ask

How do you mention condition in sequence diagram?

As in many types of UML diagrams, you can use guards to denote a condition. A guard is a boolean expression that you can write over a transition. Notice the "[pastDueBalance = 0]" condition. You can also use combined fragments for more complicated conditional logic.

How do you represent an actor in sequence diagram?

Actor (object) – this is at the top of the sequence diagram and represents an object interacting with the system. Objects, or actors, represent various roles, such as users or external systems.


1 Answers

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:

  • UML Basics: the sequence diagram (Article from Rational/IBM)
like image 95
Christophe Avatar answered Sep 27 '22 20:09

Christophe