UML 通信图中涉及的对象之间的关系

Relations between objects involved in an UML communication diagram

简而言之

在 UML 通信图中,相互交互的对象在视觉上与线相连,顺序消息可以沿线双向循环。对象之间的线通常表示链接,即关联的实例。但是对象即使没有关联也可以交换消息(例如,如果一个对象作为参数传递或 return 传递给另一个对象)。

我希望表示没有关联的对象之间的这种消息交换。但我想消除歧义并澄清,所涉及的对象之间没有直接关联。 UML 规范是否允许在不创建用户定义的构造型的情况下表达这一点?

此外,当前的 UML 规范是否在某处定义了交互通信图中对象之间关系的术语?是否可以在图中进一步指定通信对象如何相互了解?

提问前做更多研究

我目前正在重读 Grady Booch、James Rumbaugh 和 Ivar Jacobson 合着的“UML 用户指南,第 2 版”,这是一本解释 reader-友好明文。这是本书的更新版 UML 2,我可以将他们的大部分声明映射回 UML 2.5.1 规范。

然而,在关于交互的第 16 章中,他们解释了对象通过链接进行通信:

A link specifies a path along which one object can dispatch a message to another (or the same) object. (...) If you need to be more precise about how that path exists, you can adorn the appropriate end of the link with one of the following constraints:

  • association: (...) object is visible by association
  • self: (...) object is visible because it is the dispatcher of the operation
  • global: (...) object is visible because it is in an enclosing scope
  • local: (...) object is visible because it is in a local scope
  • parameter: (...) object is visible because it is a parameter

在第 19 章中,他们解释了交互中涉及的对象相互关联的通信图:

you render the links that connect these objects as the arcs of this graph. The links may have rolenames to identify them. Finally, you adorn these links with the messages that objects send and receive.

这看起来很简单。于是找了对应的UML 2.5.1规范:

因此我的问题。

规范没有明确说明,但我认为这是使用的 link 的定义:

Two objects are said to be linked, when they can interact with each other.

规范中有几个地方谈到了 links。我在11.2.3.3找到的最一般的

Each link may be realized by something as simple as a pointer or by something as complex as a network connection, and may represent the possibility of instances being able to communicate because their identities are known by virtue of being passed in as parameters, held in variables or slots, or even because the communicating instances are the same instance.

由此我得出了我的简单定义。

所以,我不同意,links 不是 “仅定义为关联实例”。这种误解可能源于这样一个事实,即指定 links 与 InstanceSpecifications 只可能用于关联:每个想要为 linked InstanceSpecifications 提供插槽的 InstanceSpecification 必须有一个关联作为分类器。但是 - links 即使未指定也可以存在。它们可以由其他模型元素指定。

这些其他link指定模型元素包括复合结构图中的连接器或交互图中的消息属性参数在class图中。

通信图只是一种显示交互的方式。它们具有与序列图相同的底层元模型实例。因此,即使生命线之间有线,也没有相应的模型元素。它们只是用来放置消息符号的位置(请参阅 Table 17.4 通信图中包含的图形路径)。

消息可以引用连接器。因此,您可以将通信图中的线视为此连接器的可视化表示。但是,没有必要明确地对连接器建模。有些工具需要连接器,但在规范中连接器是可选的。

正如你所说,没有刻板印象来描述对象如何相互认识。你需要定义你自己的。然而,还有其他可能性:生命线代表一个可连接的元素,它可以是参数或属性(或变量,但没有人使用它们)。通过查看表示的属性,可以判断是全局属性还是局部属性,是否是关联端。

话虽如此,但有一个问题。正式地,所有表示的元素必须直接或间接属于交互的上下文 class(17.12.17.5 中的 same_classifier 约束)。在我遇到的大多数情况下,这个上下文就是系统。这意味着,所有属性都必须是全局的。我与本节的作者进行了长时间的交谈,发现这个想法是,交互应该属于协作,并且通过 CollaborationUses 和 roleBindings 连接到系统。这就是 MagicDraw 自动为每个交互创建协作的原因。

这增加了另一层间接性,如我们所知,它解决了 ;-) 计算机科学中的所有问题。幸运的是,大多数工具不强制执行此规则,因此我们可以自由地让我们的生命线代表我们系统的真实组件的属性和参数。