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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Need help implementic data structures of generic objects
  5. Message-ID: <1992Dec19.192259.15137@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <724476558snx@trmphrst.demon.co.uk>
  10. Date: Sat, 19 Dec 1992 19:22:59 GMT
  11. Lines: 43
  12.  
  13. In article <724476558snx@trmphrst.demon.co.uk> nikki@trmphrst.demon.co.uk writes:
  14. >In article <1992Dec13.002551.778@informix.com> cshaver@informix.com (Craig Shaver) writes:
  15. >
  16. >> This group seems to be biased against inheritance techniques in all cases.
  17. >
  18. >No, this group merely states that heterogeneous collections (and certain 
  19. >other things) are difficult to implement in statically typed languages 
  20. >like C++, because they are incompatible with static typing.
  21.  
  22.     Heterogeneity has nothing to do with inheritance.
  23. It is perfectly feasible and only mildly naughty to have collections
  24. of objects selected from a finite set of totally different
  25. predeclared classes.
  26.  
  27.     The mechanism for this already exists, it is the union.
  28.  
  29.     union U {A a; B b; C c; };
  30.     U u[20]; // heterogenous collection
  31.     
  32. [ ... ]
  33. >
  34. >This is the major problem with such systems - you end up with hundreds of 
  35. >virtual functions in the base Object, most of which will not be used 
  36. >(indeed, have no meaning) in a particular derived class. It can work, but 
  37. >it is not elegant C++.
  38.  
  39.     Actually, it CANNOT work without downcasting and RTTI because
  40. the open/closed principle requires that it be possible to CLOSE off
  41. the class 'Object' once and for all.
  42.  
  43. >
  44. >And as for inheritance, in C++ it is for expressing an "is-a" 
  45. >relationship. Templates are for expressing genericity.
  46.  
  47.     It can and is (mis-, over-, ab-) used for very much more than
  48. this in C++, in particular, it is used as a convenient form of
  49. composition (inclusion) and also for convenient reuse.
  50.  
  51. -- 
  52. ;----------------------------------------------------------------------
  53.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  54.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  55. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  56.