representation of if else condition in collaboration diagram

6.2k views Asked by At

I was wondering, how can one represent "if" statement on a collaboration diagram?

 if (somethingShouldBeDone) {
    //multiple conditions
   // Do it
  } else {
   // Do something else
  }

Can it be represented at all? The thing is ... in my code, fair amount of conditions are checked to determine a variety of actions. If i am going to show the actions, I'd like to explicitly state that actions are caused by particular events.

If possible create an image representation of a solution.

1

There are 1 answers

2
Javier On BEST ANSWER

You may use guards for representing the conditions that must be true for a message to be passed.

The following example is equivalent to

if (x<y) {
   object2.message1();
   object3.message3();
} else {
   object2.message2();
}

Example