home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18426 < prev    next >
Encoding:
Internet Message Format  |  1992-12-25  |  2.0 KB

  1. Path: sparky!uunet!olivea!gossip.pyramid.com!pyramid!infmx!cshaver
  2. From: cshaver@informix.com (Craig Shaver)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need help implementic data structures of generic objects
  5. Message-ID: <1992Dec23.212922.10775@informix.com>
  6. Date: 23 Dec 92 21:29:22 GMT
  7. References: <1992Dec13.002551.778@informix.com> <1992Dec17.104357.3422@unix.brighton.ac.uk>
  8. Sender: news@informix.com (Usenet News)
  9. Organization: Informix Software, Inc.
  10. Lines: 31
  11.  
  12. In article <1992Dec17.104357.3422@unix.brighton.ac.uk> je@unix.brighton.ac.uk (John English) writes:
  13. >cshaver@informix.com (Craig Shaver) writes:
  14. >: It is obvious to me that you have a virtual function in the base class for 
  15. >: all functions that you need to use when dealing with 'Objects'.
  16. >: 
  17. >: If you use a function on a class that is only restricted to a certain
  18. >: sub-tree of your inheritance structure, then you know what you are using,
  19. >: ergo, you should have used that type instead of 'Object'.
  20. >
  21. >Yes, but then you end up migrating a lot of the functionality of your
  22. >hierarchy into class Object, in much the same way as widely-used data
  23. >structures end up being global in C.
  24. >
  25.  
  26. There should not be much, if any, real code in the base class virtual function.
  27. You may just want to have an error print out or exception handler to show that
  28. this function is to be implemented by a subclass.  If you can come up with 
  29. generic code, then put it in the base class and share it.  The base 'Object'
  30. at the very top of the tree should have very little functionality.  By base
  31. I mean the top of any tree type hierarchy.  
  32.  
  33. You are right to say that sometimes code sharing in the base class is like using 
  34. globals.  It is difficult to achieve and should be well thought out.  If it is 
  35. poorly formed code (most likely because of the way the classes have been designed) 
  36. then it will not be used in practice, and sub-classes will reimplement the 
  37. functionality to achieve their goals.
  38.  
  39.  
  40. -- 
  41. Craig Shaver  (cshaver@informix.com for now) (415)390-0654 (415)926-6407
  42. Productivity Group POB 60458 Sunnyvale, CA  94088
  43.