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

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!stanford.edu!unix!hplabs!hp-cv!hp-pcd!news1.boi.hp.com!cupnews0.cup.hp.com!hpscit.sc.hp.com!hplextra!hpcss01!hpwala!friedman
  2. From: friedman@hp-and.an.hp.com (joel friedman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Any inheritance experts out there? reprise
  5. Keywords: inheritance, virtual
  6. Message-ID: <4021@hpwala.wal.hp.com>
  7. Date: 18 Dec 92 16:17:18 GMT
  8. Sender: netnews@hpwala.wal.hp.com
  9. Organization: Hewlett-Packard Company
  10. Lines: 57
  11.  
  12. Hello all,
  13.  
  14. I'd like to start off by thanking the many of you who provided me info about
  15. the ARM.  I now have Stroustrup 2nd edition and it's just what I needed.  The
  16. book I originally had was Stroustrup 1st edition, not a book by Dijikstra.  My
  17. apologies for the mass confusion this caused!!
  18.  
  19. Down to business.  I need some assistance designing my class hierarchies for
  20. the following situation:
  21.  
  22. I am writing device drivers for external memory devices.  I currently have to
  23. support two types devices (say A and B), but that number could grow.  The
  24. functions each device must support are common, but the implementations used to
  25. provide them are quite different for each.  The type T below can be a char xor
  26. a short.  The following template class defines these core functions:
  27.  
  28. template <class T> class core_functions
  29. {
  30. public:
  31.    T Read cell(int address);
  32.    void Write_cell(int address, T data);
  33. };
  34.  
  35.  
  36. I want to design the hierarchy so I can easily add device C, D, E etc.  Here's
  37. the catch.  How can I do this so that the application programs only need to see
  38. the core_function class declaration; not the derived class declarations for A
  39. or B.  I need to enhance the core_functions class so that the user can call a
  40. core_functions function, and it will be directed to the implementation in the
  41. proper derived class (A or B).
  42.  
  43. If I derive A or B from core_functions, then the application must declare
  44. objects of type A or B, thus they will need to have access to the derived class
  45. declarations.
  46.  
  47. If I use A or B as a base class, then there have to be different derived
  48. core_functions classes; one derived from A, the other from B.  This prevents
  49. the user from seeing the declarations for A and B, but doesn't seem very
  50. elegant.  I want to have only 1 core_functions class.
  51.  
  52. I tried making the core_functions functions virtual.  That let me call
  53. core_functions functions, redirecting them to the implementations in A and B.
  54. This didn't prevent the application from needing the A and B class
  55. declarations, which is a requirement.
  56.  
  57. Any Ideas?? Thanks in advance.
  58. Joel
  59. -- 
  60. __________________________________________________________________________
  61. Joel Friedman           friedman@hp-and.an.hp.com           (508) 681-2709
  62.  
  63.  ///  /_ _  \\\   H E W L E T T          Imaging Systems Division
  64. (((  / //_/  )))                         3000 Minuteman Road
  65.  \\\   /    ///   P A C K A R D          Andover, Massachusetts 01810-1087
  66.  
  67. #include <standard_disclaimer.h>
  68. __________________________________________________________________________
  69.