Jump to content

Singly rooted hierarchy

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Blaisorblade (talk | contribs) at 18:44, 30 September 2007 (Add page about singly-rooted hierarchy page, a major feature of OOP-based languages, for which I could find almost no mention on Wikipedia (including C++, Java, Smalltalk and Objective C pages)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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 Stroustroup with help of [Template (programming)|template]]-based generic programming[2][3].

  1. ^ Bruce Eckel, Thinking in C++ vol. 2, Ch. 9 "Multiple inheritance": section "Perspective"
  2. ^ http://www.codeguru.com/cpp/tic/tic0246.shtml
  3. ^ Bruce Eckel, Thinking in C++ vol. 1, Ch. 16 "Introduction to Templates": section "The template solution"