14

When you draw an inheritance diagram you usually go

                         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.

bobobobo
  • 64,917
  • 62
  • 258
  • 363

7 Answers7

9

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.

Péter Török
  • 114,404
  • 31
  • 268
  • 329
5

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 :-)

Christopher Oezbek
  • 23,994
  • 6
  • 61
  • 85
5

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

Devon_C_Miller
  • 16,248
  • 3
  • 45
  • 71
  • I agree with your first part, but regarding the second part, following is possible: [Calling derived class function from base class ](http://stackoverflow.com/a/4869284/2361131) – gawkface May 05 '17 at 04:53
1

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!

John Topley
  • 113,588
  • 46
  • 195
  • 237
0

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

MK.
  • 33,605
  • 18
  • 74
  • 111
0

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

fayoh
  • 1
0

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  |  
 +---------+  
Henry Aloni
  • 617
  • 7
  • 24