How do you represent a function call as an if condition statement in Sequence Diagram?

Viewed 836

I've been drawing a sequence diagram of a module recently, while reverse engineering. I encountered a control statement, and it is like,

if (func_A() == True)
{
    DoSomeThing();
}
else
{
    DoSomeThingElse();
}

The problem is how to draw the condition?

As I mentioned, It is reverse engineering. The code cannot be modified now. I drew two diagrams, and I don't know which way is right,

The first one is this, I think it's wrong because it doesn't show the function call as a message from A to B.

enter image description here

This is the second, It shows a message func_A.

enter image description here

What do you think about to do this right?

2 Answers

To complete the other answer there is anyway a problem in the second proposal because we do not know if in [func_A() == True] you reuse the value return by the previous call or you do a second call, to avoid that add the explicit return in your diagram :

enter image description here


Out of that do you know the activities ? A sequence diagram is "just" an interaction while an activity is a behavior and can be more adapted :

enter image description here

It depends. If func_A is an operation defined in Object2 the second representation would be correct. The first does not tell where the operation is defined. Most likely (!) one would interpret func_A as an operation local to ObjectA which your code seems to say. (Btw. you have two completely different object sets AB vs. 12 in your examples.) But that is uncertain. So the 2nd variant is more explicit (and correct).

In any case I advise to not overdo SDs with fragments as "graphical programming" doesn't make things easier to read (my practical experience). It's excellent to show message flows in various collaborations. But when it comes to conditions it's getting messy very soon. A better way is to create different sub-diagrams or even use pseudo code if there are too nested if conditions. In many cases such if clauses are a good fit for state machines.

Related