home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18139 < prev    next >
Encoding:
Text File  |  1992-12-17  |  3.4 KB  |  92 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!caen!uvaarpa!cv3.cv.nrao.edu!laphroaig!cflatter
  3. From: cflatter@nrao.edu (Chris Flatters)
  4. Subject: Flattening (Was: Complexity in the eyes...V2.0)
  5. Message-ID: <1992Dec17.185151.17597@nrao.edu>
  6. Sender: news@nrao.edu
  7. Reply-To: cflatter@nrao.edu
  8. Organization: NRAO
  9. References: <1992Dec17.042207.8150@tagsys.com>
  10. Date: Thu, 17 Dec 1992 18:51:51 GMT
  11. Lines: 79
  12.  
  13.  
  14. In article 8150@tagsys.com, andrew@tagsys.com (Andrew Gideon) writes:
  15. >1.    karl@BofA.com (Karl Nicholas) asks why a consumer of classes
  16. >    would be peeking around the internals of those classes, 
  17. >    and any possible superclasses.
  18. >
  19. >    A lot of people (well...a few) provided answers.  I provided
  20. >    a couple of simplisitic ones (I was rushed!): debugging and
  21. >    understanding.
  22. >
  23. >    maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) agreed with the
  24. >    "understanding" issue.
  25. >
  26. >    I still think, however, that good documentation would solve
  27. >    that problem.  The fact that I've never seen documentation
  28. >    of sufficient quality may be significant, however.  Perhaps
  29. >    some nifty tool which reads class definitions provides a
  30. >    "flattened" interface?
  31.  
  32. [A quick aside for people who may not be familiar with the concept:
  33. A flattened class interface combines the interface of a class with
  34. its ancestors in such a way as to produce a new class, without
  35. inheritance, that behaves in the same way as the original class
  36. (apart from type compatibility, of course).]
  37.  
  38. Experience with Eiffel shows that such a tool is useful but is not, in
  39. itself, sufficient for class documentation.  I once heard Eiffel class
  40. documentation (which is usually obtained obtained by flattening a class
  41. and extracting information from it) described as being somewhere
  42. between not enough and barely adequate: this seems to be a fairly
  43. accurate description.
  44.  
  45. Unfortunately there are at least two problems in flattening C++ classes
  46. (this has really been done to death before on the net).
  47.  
  48. 1) A flattened C++ class would contain only syntactic information and
  49. would not provide any semantic information (ie. it wouldn't say
  50. what it actually does).  This information must be provided in comments
  51. which must be preserved by the flattening process.  This throws the
  52. burden of providing adequate class documentation back onto the programmer
  53. who writes the interface.  This is also true for Eiffel, although the
  54. fact that Eiffel definitions may contain semantic information (class
  55. invariants, preconditions and postconditions) make life a little easier.
  56.  
  57. 2) A C++ class behaves differently when it is called directly than
  58. when it is called through a pointer or a reference.  For example
  59.  
  60.     class A
  61.             {
  62.             ....
  63.             virtual void foo();
  64.             ....
  65.             }
  66.  
  67.     class B: public A
  68.             {
  69.             ...
  70.             virtual void foo();
  71.             }
  72.  
  73.         main()
  74.             {
  75.             B b;
  76.             A& a_ref = b;
  77.             A a = b;
  78.  
  79.             a.foo()    // calls A::foo()
  80.         a_ref.foo() // calls B::foo()
  81.             }
  82.  
  83. And there are also difficulties involving non-virtual functions: a class 
  84. access by a reference or pointer to one of its ancestors may behave like
  85. its ancestor for some member function calls and itself for others.  In
  86. general the behaviour of a C++ class will depend on the type of pointer
  87. or reference it is accessed through.  This makes a flattening a concept
  88. of dubious value for C++.
  89.  
  90.     Chris Flatters
  91.     cflatter@nrao.edu
  92.