【发布时间】:2011-01-29 02:45:55
【问题描述】:
当你画一个继承图时你通常会去
根据 ^ | 衍生的Derived 扩展 Base。那么为什么箭头会向上呢?
我以为是“Derived 与 Base 通信”通过调用其中的函数,但 Base 无法调用 Derived 中的函数。
【问题讨论】:
标签: language-agnostic inheritance
当你画一个继承图时你通常会去
根据 ^ | 衍生的Derived 扩展 Base。那么为什么箭头会向上呢?
我以为是“Derived 与 Base 通信”通过调用其中的函数,但 Base 无法调用 Derived 中的函数。
【问题讨论】:
标签: language-agnostic inheritance
关于 ascii 符号的说明 - 来自 the wonderful c2 wiki page 您可以考虑以下 ascii 图表箭头用于
IS_A relation (inheritance)
+-------+ +-----------+
| Base | | Interface |
+---^---+ +-----^-----+
/_\ /_\ _
| : (_) OtherInterface
| : |
| : |
+---------+ +----------------+
| Derived | | Implementation |
+---------+ +----------------+
对
HAS_A relation (containment)
+-------+
| User |
+-------+
|
|
|
\ /
+----V----+
| Roles |
+---------+
【讨论】:
将箭头读作“继承自”,这是有道理的。或者,如果您愿意,可以将其视为可以进行方向调用。
【讨论】:
在 UML 中,箭头称为“泛化”关系,它仅表示 Derived 类的每个对象也是 Base 类的对象。
从上层建筑2.1.2:
A Generalization is shown as a line with a hollow triangle as an
arrowhead between the symbols representing the involved classifiers.
The arrowhead points to the symbol representing the general
classifier. This notation is referred to as the “separate target style.”
虽然不是这个问题的真正答案:-)
【讨论】:
AFAIK 的原因之一是符号一致性。所有其他有向箭头(依赖、聚合、组合)都从依赖指向被依赖。
在继承中,B 依赖于 A,但反之则不然。因此箭头从 B 指向 A。
【讨论】:
B => A 的意思是“每个 B 都意味着一个 A”。
我一直认为 B 比 A 有更多的东西(子类通常比超类有更多的方法),因此 B 得到箭头的宽端而 A 得到尖头!
【讨论】:
我觉得重点是表达“泛化”:A是B的泛化。
这样箭头表达了与扩展中相同的概念,但走的是“正确”的方向
【讨论】:
B是主语,A是宾语,动作是“继承”。所以 B 作用于 A,因此箭头的方向。
【讨论】: