2

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.

WannaBeCoder
  • 1,280
  • 2
  • 17
  • 40

1 Answers1

3

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

Javier
  • 12,100
  • 5
  • 46
  • 57
  • thank you, and one more question, if there are n messages from object1 to object2 satisfying the if condition, do i need to mention [x – WannaBeCoder Dec 27 '13 at 04:40
  • I cannot think of other way, but perhaps a sequence diagram is more appropriate for conveying that behavior. – Javier Dec 27 '13 at 04:42