Adam Taylor
Adam Taylor

Reputation: 7793

How to represent a call being made in a loop in a sequence diagram?

I'm creating a sequence diagram, and one of the classes is being observed by another class. The observed class is calling update in the observer every 5 seconds in a loop. I need to show this in the sequence diagram. Is there a way to show it looping indefinitely out of sequence as it were?

Or does it not make sense in the context of a sequence diagram; should I not include it? Or should I include it in a different type of diagram?

Upvotes: 64

Views: 157349

Answers (2)

joel.neely
joel.neely

Reputation: 30973

You can use a box enclosing the message send arrow (and whatever else is inside the same repetitive construct).

See this tutorial for an example.

sequence diagram with loop link to larger image (archived)

Upvotes: 70

Themelis
Themelis

Reputation: 4255

Just adding a clearer picture because this one at @joel.tony's answer is damn blur.

enter image description here

As you can see the loop happens inside the frame called loop n. There is a guard, array_size, which controls the loop's iterations.

In conclusion the sequence of the messages inside the loop n frame (those between DataControl and DataSource objects) will happen array_size times.

Upvotes: 52

Related Questions