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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!rational.com!thor!rmartin
  3. From: rmartin@thor.Rational.COM (Bob Martin)
  4. Subject: Re: Multiple Header Files Problem
  5. Message-ID: <rmartin.722283008@thor>
  6. Sender: news@rational.com
  7. Organization: Rational
  8. References: <1992Nov10.164547.19059@mprgate.mpr.ca> <5189@holden.lulea.trab.se> <1240@saxony.pa.reuter.COM>
  9. Date: Fri, 20 Nov 1992 18:10:08 GMT
  10. Lines: 44
  11.  
  12. dgil@pa.reuter.COM (Dave Gillett) writes:
  13.  
  14. |     It's pretty hard to get into this fix except by making heavy use of
  15. |inline methods.  Dare I suggest that anyone who regards this as a "very
  16. |serious" problem is *probably* inlining too much? 
  17.  
  18. excessive inline-ing is one of the most common flaws made by novice
  19. users of C++.  The tempatation to inline is strong, and the
  20. disadvantages are not obvious.  This attitude can lead a development
  21. team into a very nasty situation involving long convoluted dependency
  22. cycles.  It is not always easy to figure out how to break them.
  23.  
  24. As a basic rule of thumb, functions which access the members of other
  25. classes should not be inlined.  If this rule is followed consistently,
  26. then inlining will never cause a dependency cycle.
  27.  
  28. The other source of dependency cycles that you mentioned was
  29. "containment by value".  i.e.
  30.  
  31.     class A
  32.     {
  33.       public:
  34.         B itsB;
  35.     };
  36.  
  37.     class B
  38.     {
  39.       public:
  40.         A itsA;
  41.     };
  42.  
  43. This can be broken by containing one or both members by reference.
  44. (i.e. use pointers or references instead of values).  Such a practice
  45. also brings the benefit that the contained object can be polymorphic.
  46. Objects contained by value cannot be polymorpic, but objects contained
  47. by reference can.
  48.  
  49. Thus, another rule of thumb is: "where possible, contain by
  50. reference."
  51. --
  52. Robert Martin                        Training courses offered in:
  53. R. C. M. Consulting                       Object Oriented Analysis
  54. 2080 Cranbrook Rd.                        Object Oriented Design
  55. Green Oaks, Il 60048 (708) 918-1004       C++
  56.