UML Class 图:导航和所有权的区别

UML Class diagram: difference between Navigation and Ownership

我阅读了

中的帖子

但是我仍然不清楚 UML class 图关联的“导航”和“所有权”之间的区别。此外,UML 2.5 也同时发布。

规范规定如下:

Association ends owned by classes are always navigable, while those owned by associations may be navigable or not.

  1. 这意味着,下面的例子c是无效的。示例 a 和 b 是有效的,在这两种情况下,右端都是可导航的。但是,在示例 b 中,左端不可导航。

    我说得对吗?

  2. 导航和所有权之间的语义区别是什么?导航是访问相反 class 而所有权强制 class 具有属性的“通用”方式吗?

规格说

Dot notation is used to denote association end ownership, where the dot shows that the Class at the other end of the line owns the Property whose type is the Class touched by the dot.

所以ab是有效的,而c是奇怪的。假设左边开始 class A,右边开始 class B。如果 a A 拥有类型为 B 的 属性,因此它可以导航到它。 Case b 显式添加了 A 可以导航到 B 的信息,这通过使用点已经很明显了。如果 c B 拥有 A 类型的 属性(因此可以导航)。此外,您指示从 AB 的导航但未显示所有权。所以这很奇怪。

所有权只是表示有一些东西(指针)可以导航到另一个对象。引用规范(第 126 页):

Navigation arrows may be shown, but if shown, they shall agree with the navigation of the Association’s ends.

及更高版本(第 201 页):

In practice, it is often convenient to suppress some of the arrows and crosses that signify navigability of association ends. A conforming tool may provide various options for showing navigation arrows and crosses. As with dot notation, these options apply at the level of complete diagrams.

  • Show all arrows and crosses. Navigation and its absence are made completely explicit.
  • Suppress all arrows and crosses. No inference can be drawn about navigation.
  • Suppress all crosses. Suppress arrows for Associations with navigability in both directions, and show arrows only for Associations with one-way navigability. In this case, the two-way navigability cannot be distinguished from situations where there is no navigation at all; however, the latter case occurs rarely in practice.

导航没有实际用途(在大多数情况下)。您通过添加角色名称来显示导航,这些名称清楚地表明 AB 视为 role。末尾有一个带叉号的符号,明确禁止导航。这在某些情况下可能会有用。

可能会注意到,与“所有权”(使用得更多)相比,规范对“导航”(只是出现的事件)相当沉默。这可能是最近引入所有权的事实。