使用 UML 符号的 ER 图和 UML Class 图有什么区别?

What is the difference between ER Diagram using UML notation and UML Class Diagrams?

我有一个项目需要我创建一个 UML Class 图。我从同一项目中的先前任务中得到的是一个使用 UML 表示法的 ERD。另外值得注意的是,该项目与数据库有关,并且没有太多代码,因此根据其他代码创建class图可能不是这里的主要objective。

我尝试使用谷歌搜索“如何将 erd 转换为 class 图”,但所有搜索结果仅显示如何使用鱼尾纹表示法将 ERD 转换为 UML Class 图。

我还用 Google 搜索了 UML 符号 ERD,发现 this site 说,

In UML notation, entities are modeled as a “class” with an Entity stereotype.

这是否意味着使用 UML 符号的 ERD 与 UML Class 图相同?如果不是,有什么区别?

注意:我知道已经有关于 ERD 和 Class 图之间的区别的问题,但我特别询问关于 ERD using UML notation.

在 Chen 的原始 ERD 符号属性中,椭圆连接到它们用矩形表示的实体,它们可以具有用 losanges 表示的关系。由于属性众多,这导致图表非常庞大和复杂。

Crow's Feet 符号因此变得更受欢迎,因为它允许以更紧凑的方式表达相同的模型,将属性与其实体一起分组在矩形中,并使用基数的直观视觉表示。但现在 UML 是建模者的通用语言,很容易考虑其他替代方案。

您的 linked source 建议将实体、属性、关系的核心 ERD 概念非常自然地映射到 UML class、属性和关联中:

(...) entities are modeled as a “class” with an Entity stereotype.

(...) attributes can be arranged in a box style (...)

Relationships are shown as a single solid line connecting the two entities. The minimum and maximum cardinalities are shown along the line and verb phrases can be added to completely characterize the nature of the relationship.

事实上,UML 中 ERD 图最合适的表示法是 class 图。

但要注意细微的语义差异。例如:

  • 在 UML 中,任何 属性(您的映射与属性相关的内容)都可以在框内(如您所说的属性)或相关联的 class(正如您所说的实体)具有一个拥有的关联端。

  • UML classes 应该有行为(这是因为底层的 OOP 概念)。没有行为的 class 可能会被 UML reader 误解为糟糕的设计(贫血领域模型)。 «Entity» 构造型不足以消除歧义,因为它通常在 UML 上下文中与 Entity-Control-Boundary 范式相关联,后者也期望实体具有行为。也许您使用更明确的刻板印象定义 UML 概要文件,例如 «Data-Entity»

  • 您的链接源误导了 关于 UML 中的鱼尾纹换位:您可以在 UML 中的关联上添加动词短语,但在中间 oc association and with 和 with 文本旁边的箭头表示阅读的方向。在 UML 中,关联端的文本是完全不同的东西:它被称为“角色”。 ERD 图中的等效项是在另一端的实体中包含一个具有角色名称的属性(并且对应于标识另一个实体的主键)。

可以在 Wikipedia article on ERD.

的侧边栏中找到有关如何以不同符号记录 ERD 概念的更好资源。

编辑: 更一般的文章“A framework for transforming structured analysis and design artifacts to UML": it mentions that in addition, ERD diagrams sub-type relations should be transformed in UML generalization 下提出了映射算法条件是 IsA 关系。