Interlacing conditions

0 votes
asked 5 days ago in Question / help by maartensson (120 points)

Hi, I am new to PlantUML and UML in general, I am learning at UNI now and I like PlantUML much more than the program they want us to use there, but I have one problem, because I made an activity diagram in the new (beta) syntax, and i got something like this.
PlantUML (beta) actitivy diagram

@startuml

start

:Administrer øvelser;

repeat

if (er der øvelser) then (nej)

:Tilføj øvelse;

else (ja)

:Vælg handling;

if ()

-> [Tilføj valgt];

:Tilføj øvelse;

else ()

-> [Slet valgt];

:Slet øvelse;

endif

endif

:Øvelse ændret;

repeat while (Afslut) is (Nej)

-> Ja;

stop

@enduml

My teacher was not very happy with this because the one called "Tilføj øvelse" is the same but it repeats twice.

I tried making it in the old syntax and i got something like this:

@startuml

(*) -> "Administrer øvelser"

if "er der øvelser" then 

-->[ja] "Vælg handling"

if "" then

->[tilføj valgt] "Tilføj øvelse"

else

-->[fjern valgt] "Fjern øvelse"

endif

else

-->[nej] "Tilføj øvelse"

endif

"Tilføj øvelse" -> "Øvelse ændret"

"Fjern øvelse" -> "Øvelse ændret"

if "Afslut" then

-->[nej] "Administrer øvelser"

else

-->[ja] (*)

endif

@enduml

It just looks super messy, and there was a lot of fuzz to get the arrows to point in the right direction.

So my question is:

Is it possible to make something like the first diagram where we have two conditions but where Tilføj øvelse only appears one time.

1 Answer

+1 vote
answered 4 days ago by Serge Wenger Work (11,800 points)

Hi,

The first diagram is like you can code it with "standard" language like C, C++, C#, etc. An activity can be a "function" and used 2 times.

If you need to code like the second one, you need a "Goto" and it is not really a best practice.

As workaround you can use Connector and you feally see the "Goto"

@startuml
start
:Administrer øvelser;
repeat
if (er der øvelser) then (nej)
(A)
:Tilføj øvelse;
else (ja)
:Vælg handling;
if ()
-> [Tilføj valgt];
(A)
Detach
':Tilføj øvelse;
else ()
-> [Slet valgt];
:Slet øvelse;
endif
endif
:Øvelse ændret;
repeat while (Afslut) is (Nej)
-> Ja;
stop
@enduml

 

commented 4 days ago by maartensson (120 points)

Hi Serge, Thank you so much for the reply!

I thought about the GoTo option as well, but i ended up exporting the code as an .svg file and edited the file in Inkscape, to get the look that my teacher was requesting. 

Edited in Inkscape

As i already said, I don't know alot about UML yet, and I am not sure how much the activity diagram and the code should look like each other. For instance I don't know what is best. Either to write a simple activity diagram where the actions don't repeat themselves, or to keep the code and the diagram synchronous and then let actions repeat as many times as necesary. Maybe i should just split the usecase into several smaller usecases.

A big exampleIn this big example you can see the one with red color is the one I used before but as a part of a bigger usecase, and it is repeating it self. If I made a goto or a line here then it would jump out of a loop so I guess the best thing would be to keep the repetition of activities, or to divide the usecases into smaller parts.

We will be coding in Java, so I think it is similar to the C languages.

Thank you very much for the help

...