views:

64

answers:

3

I'd like to know how to express in a Communication Diagram something like:

foreach (User user in UsersCatalog) {
    list.add(user.getId());
}

I actually have something like the following

alt text

(Utilizador = User)

but as you'll notice it does not represent well the fact that I am doing something like a loop.

How can I accomplish this?

+1  A: 

Why don't you complement this diagram with a sequence diagram?. Sequence diagrams are better to express the temporal relation between events and have a predefined notation to express loops.

Jordi Cabot
+1  A: 

Just define getId() : int with an asterisk(*):

1.4 *getId()

for the given example.

devoured elysium
A: 

As Jordi stated, for describing loops sequence diagrams are better. The reason is that you want to describe an interaction between objects communicating using message passing. For this purpose UML defines different interaction diagrams focusing on different aspects of the interaction. Sequence diagrams focus on sequences of messages passed between objects (lifelines), so it makes sense to capture sending messages in a loop - sequence. Communication diagrams focus on communicating objects, which send certain messages to each other. These diagrams are not useful for modeling loops, because they depict only what kind of messages is sent and in which order. However if you use communication diagram for a good purpose and just want to include loop you have in your code, you should follow elysiums advice, but bear in mind, that asterisk means there will be unknown number of messages, so you should add an expression (ideally OCL) which will capture the condition for the loop. For more information consult those: http://www.smartdraw.com/resources/tutorials/uml-collaboration-diagrams/ http://en.wikipedia.org/wiki/Unified_Modeling_Language#Interaction_diagrams

Gabriel Ščerbák