2
votes

For example, I have a code like this:

if (morning) {
    if (beforeTenAM) {
        System.out.println("Go back to sleep"); }
    else { 
        System.out.println("Wake up!"); }
}
else {
    System.out.println("It's not morning anymore");
}

How can I represent this nested if else statement in a UML sequence diagram? Is it possible to do so? Or is a communication diagram better in this case?

2

2 Answers

4
votes

Well, you can do that with a fragment in a SD like

enter image description here

As you can see it's geeting crowded soon and the code is more clear than that. Don't be tempted to start graphical programming. SDs are here to give an overview of collaborating objects. Leave the rest to coders and eventually provide some pseudo code.

An AD delivers a more business oriented aspect:

enter image description here

0
votes

two possibilities :

  • an activity using decision nodes

  • a sequence diagram using combined fragments