Wednesday, July 21, 2010

Class Inheritance


Public Inheritance:
-------------------
     Base            Client
    +----------+    +-------+
+---|Public<========|       |
|+--|Protected |    |       |
||  |Private   |    |       |
||  +----------+    +-------+
||
||    Derived 1      Client 1
||   +----------+   +-------+
+|-->|Public<=======|       |
+--->|Protected |   |       |
     |Private   |   |       |
     +----------+   +-------+

Protected Inheritance:
----------------------
     Base            Client
    +----------+    +--------+
+---|Public<========|        |
|+--|Protected |    |        |
||  |Private   |    |        |
||  +----------+    +--------+
||
||    Derived 1      Client 1
||   +----------+   +--------+
||   |Public<=======|        |
++-->|Protected |   |        |
     |Private   |   |        |
     +----------+   +--------+

Private Inheritance:
--------------------
     Base            Client
    +----------+    +--------+
+---|Public<========|        |
|+--|Protected |    |        |
||  |Private   |    |        |
||  +----------+    +--------+
||
||    Derived 1      Client 1
||   +----------+   +--------+
||   |Public<=======|        |
||   |Protected |   |        |
++-->|Private   |   |        |
     +----------+   +--------+

The single line arrows show what becomes brought into the derived class's access levels.  The double line arrows show what the clients see.

No comments:

Post a Comment