uml - 如何在 UML 类图中表达 "returns a"关系?

标签 uml

我想在 UML 中(直观地)表达 class Foo 返回 class BarBar 对象在 Foo 的方法之一中创建并作为结果返回。

不知道是用依赖关系还是关联关系。有什么建议吗?

编辑

我应该澄清一下,我正在处理的 UML 图不包含任何类属性或操作。它只是作为显示类之间关系的概述。属性和操作的描述已经从源代码中生成(通过 Doxygen)。

编辑 2

我应该进一步澄清,我想从类图中展示这种关系。我很抱歉从一开始就不清楚。

编辑 3

在进一步挖掘和查看示例后,我意识到记录 Foo 创建 Bar 更为重要。 Foo 的方法之一返回 Bar 这一事实是一个实现细节,我可以将其从我的类图中省略。所以现在,我的问题是:在类图中显示“Foo 创建 Bar”关系的最佳方式是什么?

最佳答案

正如我在第三次编辑中提到的,我意识到记录 Foo 创建 Bar 的关系更为重要。 Foo 的一些方法返回 Bar 的事实最好留给 Doxygen 文档(无论如何在我的情况下)。

正如其他人所说,Foo 返回 Bar 这一事实也可以表示在 Foo 类的操作部分,或者行为图中。但在我的问题中,我限制自己只使用类图,而没有列出属性和操作。

我已经做了一些挖掘,发现 UML 有 <<create>>为使用依赖项预定义的构造型,如图所示 here作为

+------------+               +------------+
|            |  <<create>>   |            |
| Datasource +-- -- -- -- -->+ Connection |
|            |               |            |
+------------+               +------------+

<<create>> UML 2.4.1 Superstructure specification 中描述了刻板印象, 第 704 页为:

A usage dependency denoting that the client classifier creates instances of the supplier classifier.

使用依赖(UML 2.4.1 上层结构,第 139 页)

a relationship in which one element requires another element (or set of elements) for its full implementation or operation.

此外:

The usage dependency does not specify how the client uses the supplier other than the fact that the supplier is used by the definition or implementation of the client.

UML 规范也有 <<instantiate>>预定义的构造型,定义为:

A usage dependency among classifiers indicating that operations on the client create instances of the supplier.

<<create>> 之间似乎有一些重叠和 <<instantiate>>刻板印象。

关于uml - 如何在 UML 类图中表达 "returns a"关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29307216/

相关文章:

android - 多个场景的 Activity 图有多少? (UML 2.0)

objective-c - 使用 Xcode 生成 UML 代码

java - 具有代码生成功能的开源 UML eclipse 插件

Java : how to notify objects ?(其中模式/...)

interface - MagicDraw - 使用真正的 UML 符号显示界面

带有 uml 的 Java 项目

java - UML类图主类

java - 用于 Maven javadoc 生成的 UmlGraph 与 APIViz

uml - guest 、用户、版主、管理员 - vs - 用户(角色 : guest, 用户、版主、管理员)

uml - 在 PlantUML 中绘制约束