home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!rational.com!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Subject: On Trees vs. Forests. was: Should I use a generic object...
- Message-ID: <rmartin.722279904@thor>
- Sender: news@rational.com
- Organization: Rational
- References: <1992Nov19.165529.23862@informix.com> <5242@holden.lulea.trab.se>
- Date: Fri, 20 Nov 1992 17:18:24 GMT
- Lines: 53
-
- The discussion of tree vs. forest models is quite interesting.
-
- Definitions:
-
- Tree: A class library whose component classes all derive from
- a common base class; typically named "Object".
-
- Forest: A class library whose component classes do not have a
- common ancestor. Inheritance may exist, but the
- absence of a common base means that there are many
- unrelated inheritance hierarchies, or trees, thus the
- name.
-
- The tree model has the advantage that every object will inherit some
- baseline functionality. For example, every object may inherit the
- ability to print standard debugging messages, or the ability to know
- the name of its class. Every object could inherit the ability to
- Print or Dump or Gargle with salt water.
-
- Among the disadvantages of the tree model are the fact that each of
- the objects will carry along a little bit of excess baggage.
- Regardless of whether the object uses the inherited features of
- Object, it will carry those features along with it. This is perhaps a
- bit inefficient.
-
- Worse, two tree libraries constructed with different Objects as the
- base class will almost certainly be incompatible.
-
- The forest model has the advantage that each of the inheritance
- hierarchies within it are independent. This makes for slightly
- smaller objects, and for more compatibility between libraries. Two
- forest libraries can be merged into a single project with far less
- difficulty than two tree liraries.
-
- The disadvantages of the forest model are the lack of common paradigms
- for dealing with the objects. Each object may have a Print or Gargle
- method, but there is no common abstract class which encapsulates that
- ability. Moreover, since reqularity is not enforced, Print and Gargle
- may have different signatures and behave in different ways.
-
- For my part, I prefer forest models. I don't like the idea of a big
- mamma object on top of everything. I feel that it makes the code less
- mobile and less compatible with others. But I have used the tree
- model in the past, and acknowledge some of its benefits. But I think
- that the forest model imposes fewer constraints and makes the code a
- bit easier to work with.
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-