21
votes

I am trying to design an activity diagram (UML) for a networked tic tac toe game that I developed, with sockets. I am using activity partitions (swimlanes). So, there is three partitions: Client1, Server, and Client2.

The diagram is looking good, except I do not know how to represent loop structures.

If you look at this link: activity diagram, and look at the last diagram on the page (Partition), that is the type of activity diagram that I am working with.

Does anyone know how I can represent loops? Thanks!

3
You need to elaborate on your problem domain.Martin Spamer
UML activity diagram might able to explain loops - in a procedural way. But I can see a shortage what UML will fail to describe functional expression like (map/foreach/reduce) in a simply way.Dennis C

3 Answers

11
votes

Look further down the page you link to for Expansion Region. Use one with the iterative keyword.

An expansion region is a structured activity region that executes multiple times. Input and output expansion nodes are drawn as a group of three boxes representing a multiple selection of items. The keyword "iterative", "parallel" or "stream" is shown in the top left corner of the region.

2
votes

Maybe I'm missing something but why not just using the exit flow of the last activity in the loop as input flow for the first activity in the loop (with a guard condition to finish the loop when appropriate)

1
votes

If you are using a set of data for the input, then the "Expansion Region" is perfect. For instance, you want to convert in Euro all your incomes. Then, it's like a for().

But if you want to have something similar to a while(), you must use rounded rectangle and diamonds, with a feedback loop.

For instance: [Play blackjack] ->if I win --> I stop ->else --> i start again.

I think that the only efficient ways to do loop in an activity diagram.

You can have a look at the loop node. But I'm not sure how well defined it is in the OMG spec.