Not every hierarchy is a tree as you mention. This can be solved in several ways:
- C++ and other languages (Perl among them) offer multiple inheritance, this means that a class can have multiple base classes. If you start drawing diagrams, you'll notice this can get quite nasty (or at least very tricky) if one exagerates.
- Java offers interfaces: one can view this as a kind of contract. Certain functions must be implemented in the class that is to adhere to the interface. This can be done in OO languages that don't support multiple inheritance, but also in C++.
The approach using interfaces has the advantage that one can "attach" properties to a tree. A person could implement the trainspotter interface and offer the method
seenWhatTrainsToday().
The issue has been discussed recently in this node, but you might also be interested in the following book:
@book{Lau01,
author = {Y.-T.\ Lau},
title = {The art of objects: object-oriented design and architecture},
publisher = {Addison-Wesley},
year = {2001},
series = {Object technology series},
address = {Upper Saddle River, NJ}
}
Just my 2 cents, -gjb-