绘制继承图时,通常会进行
Base ^ | Derived
Derived extends Base。为什么箭头会上升?
我认为这意味着“Derived与Base通信”通过调用其中的函数,但Base不能调用Derived中的函数。
答案 0 :(得分:6)
AFAIK其中一个原因是符号一致性。所有其他有向箭头(依赖,聚合,组合)都指向从属的依赖性。
在继承中,B依赖于A但不依赖于A.因此箭头指向B到A.
答案 1 :(得分:2)
在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.”
虽然问题不是答案: - )
答案 2 :(得分:2)
将箭头视为“继承自”,这是有道理的。或者,如果您愿意,可以将其视为可以调用的方向。
答案 3 :(得分:1)
我总是把它想象成B里面有更多的东西然后是A(子类通常比超类有更多的方法),因此B得到箭头的宽端,A得到尖端!
答案 4 :(得分:0)
B是主语,A是对象,动作是“继承”。所以B作用于A,因此是箭头的方向。
答案 5 :(得分:0)
我认为重点是表达“概括”:A是B的概括。
这样箭头表达的概念与扩展名相同,但是采用“正确”的方式
答案 6 :(得分:0)
关于ASCII符号的注释-来自the wonderful c2 wiki page 您可以考虑使用以下ascii图箭头
IS_A relation (inheritance)
+-------+ +-----------+
| Base | | Interface |
+---^---+ +-----^-----+
/_\ /_\ _
| : (_) OtherInterface
| : |
| : |
+---------+ +----------------+
| Derived | | Implementation |
+---------+ +----------------+
vs
IS_A relation (containment)
+-------+
| User |
+-------+
|
|
|
\ /
+----V----+
| Roles |
+---------+