home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16658 < prev    next >
Encoding:
Text File  |  1992-11-20  |  2.7 KB  |  65 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!rational.com!thor!rmartin
  3. From: rmartin@thor.Rational.COM (Bob Martin)
  4. Subject: On Trees vs. Forests.  was: Should I use a generic object...
  5. Message-ID: <rmartin.722279904@thor>
  6. Sender: news@rational.com
  7. Organization: Rational
  8. References: <1992Nov19.165529.23862@informix.com> <5242@holden.lulea.trab.se>
  9. Date: Fri, 20 Nov 1992 17:18:24 GMT
  10. Lines: 53
  11.  
  12. The discussion of tree vs. forest models is quite interesting.
  13.  
  14. Definitions:
  15.  
  16.     Tree:    A class library whose component classes all derive from
  17.         a common base class; typically named "Object".
  18.  
  19.     Forest:    A class library whose component classes do not have a
  20.         common ancestor.  Inheritance may exist, but the
  21.         absence of a common base means that there are many
  22.         unrelated inheritance hierarchies, or trees, thus the
  23.         name.
  24.  
  25. The tree model has the advantage that every object will inherit some
  26. baseline functionality.  For example, every object may inherit the
  27. ability to print standard debugging messages, or the ability to know
  28. the name of its class.  Every object could inherit the ability to
  29. Print or Dump or Gargle with salt water.
  30.  
  31. Among the disadvantages of the tree model are the fact that each of
  32. the objects will carry along a little bit of excess baggage.
  33. Regardless of whether the object uses the inherited features of
  34. Object, it will carry those features along with it.  This is perhaps a
  35. bit inefficient.  
  36.  
  37. Worse, two tree libraries constructed with different Objects as the
  38. base class will almost certainly be incompatible.
  39.  
  40. The forest model has the advantage that each of the inheritance
  41. hierarchies within it are independent.  This makes for slightly
  42. smaller objects, and for more compatibility between libraries.  Two
  43. forest libraries can be merged into a single project with far less
  44. difficulty than two tree liraries.
  45.  
  46. The disadvantages of the forest model are the lack of common paradigms
  47. for dealing with the objects.  Each object may have a Print or Gargle
  48. method, but there is no common abstract class which encapsulates that
  49. ability.  Moreover, since reqularity is not enforced, Print and Gargle
  50. may have different signatures and behave in different ways.
  51.  
  52. For my part, I prefer forest models.  I don't like the idea of a big
  53. mamma object on top of everything.  I feel that it makes the code less
  54. mobile and less compatible with others.  But I have used the tree
  55. model in the past, and acknowledge some of its benefits.  But I think
  56. that the forest model imposes fewer constraints and makes the code a
  57. bit easier to work with.
  58.  
  59.  
  60. --
  61. Robert Martin                        Training courses offered in:
  62. R. C. M. Consulting                       Object Oriented Analysis
  63. 2080 Cranbrook Rd.                        Object Oriented Design
  64. Green Oaks, Il 60048 (708) 918-1004       C++
  65.