How to express loops in Communication Diagrams?

筅森魡賤 提交于 2019-12-11 11:35:51

问题


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


回答1:


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

1.4 *getId()

for the given example.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/2985601/how-to-express-loops-in-communication-diagrams

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!