开发者

Why does the arrow go up in inheritance?

When you draw an inheritance diagram you usually g开发者_如何学Co

                         Base
                           ^
                           |
                        Derived

Derived extends Base. So why does the arrow go up?

I thought it means that "Derived communicates with Base" by calling functions in it, but Base cannot call functions in Derived.


AFAIK one of the reasons is notational consistency. All other directed arrows (dependency, aggregation, composition) points from the dependant to the dependee.

In inheritance, B depends on A but not vice versa. Thus the arrow points from B to A.


In UML the arrow is called a "Generalization" relationship and it only signals that each object of class Derived is also an object of class Base.

From the superstructure 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.”

Not really an answer though to the question :-)


Read the arrow as "inherits from" and it makes sense. Or, if you like, think of it as the direction calls can be made.


I always think of it as B having more stuff in it then A (subclasses often have more methods than superclasses), hence B gets the wide end of the arrow and A gets the pointy end!


B is the subject, A is the object, action is "inherit". So B acts on A, hence the direction of the arrow.


I think the point is to express "generalization": A is a generalization of B.

This way the arrow expresses the same concept as in extension but goes the "right" way


A note about ascii notation - from the wonderful c2 wiki page You might consider the following ascii diagram arrow for

IS_A relation (inheritance)

  +-------+         +-----------+
  | Base  |         | Interface |
  +---^---+         +-----^-----+
     /_\                 /_\     _
      |                   :     (_) OtherInterface
      |                   :      |
      |                   :      |
 +---------+      +----------------+
 | Derived |      | Implementation |
 +---------+      +----------------+   

vs

HAS_A relation (containment)

  +-------+   
  | User  |       
  +-------+   
      |    
      |       
      |       
     \ /       
 +----V----+  
 |  Roles  |  
 +---------+  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜