llamaro25
llamaro25

Reputation: 692

How do I draw a UML diagram with nested if statements?

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?

Upvotes: 4

Views: 8568

Answers (2)

qwerty_so
qwerty_so

Reputation: 36313

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

Upvotes: 8

bruno
bruno

Reputation: 32596

two possibilities :

  • an activity using decision nodes

  • a sequence diagram using combined fragments

Upvotes: 0

Related Questions