开发者

How to express loops in Communication Diagrams?

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

foreach (User user in Us开发者_运维知识库ersCatalog) {
    list.add(user.getId());
}

I actually have something like the following

alt text http://img691.imageshack.us/img691/9213/semttuloyc.png

(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?


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

1.4 *getId()

for the given example.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜