Singly-rooted hierarchy
From Wikipedia, the free encyclopedia
The singly-rooted hierarchy, in object-oriented programming, is a characteristic of most (but not all) OOP-based programming languages. In most such languages, in fact, all classes inherit directly or indirectly from a single root, usually with a name similar to Object; all classes then form a common inheritance hierarchy.
This idea was introduced first by Smalltalk, the first OOP language, and was since used in most other ones (notably Java and C#).
This feature is especially useful for container libraries - since you want to be able to put anything in a container, it is enough to allow putting an Object in it to be done. A notable exception is C++, where (mainly for compatibility with C and efficiency) there is no single object hierarchy. The mentioned container problem, in C++, has been first tackled with Multiple inheritance[1], and then instead solved by Bjarne Stroustrup with help of template-based generic programming[2][3].
- ^ Bruce Eckel, Thinking in C++ vol. 2, Ch. 9 "Multiple inheritance": section "Perspective"
- ^ MFC Programmer's SourceBook : Thinking in C
- ^ Bruce Eckel, Thinking in C++ vol. 1, Ch. 16 "Introduction to Templates": section "The template solution"