home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20013 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  3.2 KB

  1. Xref: sparky comp.lang.c++:20013 comp.object:5087
  2. Path: sparky!uunet!charon.amdahl.com!netcomsv!netcomsv!ulogic!hartman
  3. From: hartman@ulogic.UUCP (Richard M. Hartman)
  4. Newsgroups: comp.lang.c++,comp.object
  5. Subject: Re: HELP : Array of objects of diff classes ??
  6. Message-ID: <927@ulogic.UUCP>
  7. Date: 27 Jan 93 19:06:26 GMT
  8. References: <1993Jan19.112059.2882@ucc.su.OZ.AU>> <CAMPBELL.93Jan22132319@analysis.src.honeywell.com> <mcampbel.727881449@eola.cs.ucf.edu>
  9. Followup-To: comp.lang.c++
  10. Organization: negligable
  11. Lines: 61
  12.  
  13. In article <mcampbel.727881449@eola.cs.ucf.edu> mcampbel@cs.ucf.edu (Mike Campbell ) writes:
  14. |campbell@src.honeywell.com (Terry Campbell) writes:
  15. |
  16. |
  17. |>In article <1993Jan19.112059.2882@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  18. |
  19. |>>Dear Everybody,
  20. |>>
  21. |>>
  22. |>>    I have a problem related to programming in an object oriented fashion.
  23. |>>    Here`s the problem description :
  24. |>>        There is an object class called Holder. The object holder can hold various
  25. |>>        things : Pencils, Pens, Erasers etc. I`ve declared different classes for
  26. |>>        these things ( class PENCIL, class PEN, class ERASER etc. ). 
  27. |>>
  28. |>>        The user of this program will choose at the runtime what objects to put
  29. |>>        in the holder. The problem is how do i store this information (i.e the
  30. |>>        contents ) in class HOLDER. I cannot create a single array of objects
  31. |>>        because each object is of different class.
  32. |>>    
  33. |
  34. |>I assume that it reasonable to allow Holder to hold any one of these objects
  35. |>because there is some similarity between these objects.  e.g., they are all
  36. |>drawing tools or whatever.  This concept of similarity should be captured by
  37. |>classifiying each of these item classes as subclasses (or specializations) of
  38. |>the common class (e.g., drawing_object - which may be abstract).  Then, the
  39. |>Holder class simply has to be declared to be able to hold objects of type
  40. |>drawing_object.  Then, any instance of PENCIL, PEN, ERASER and any other class
  41. |>derived from drawing_object cam be held by a Holder instance.  Aggregates can
  42. |>hold heterogeneous collections etc.
  43. |
  44. |I've been following this thread with some interest, and I find your reply 
  45. |interesting.  
  46. |
  47. |I agree with your analysis of the problem re: subclasses, however, what if
  48. |you buy/purchase/steal classes from multiple vendors/coworkers/victims ?
  49. |They necessarily will not have a common base class.  (Or is this correctly
  50. |deemed "superclass?")
  51. |
  52. |Borland does this - they have a common base class, "Object", as I recall, and
  53. |all of the storage classes can hold 'objects'.  This allows the storage 
  54. |classes to hold just about anything in their provided class library, as every-
  55. |thing is derived from the 'object' class.
  56. |
  57. |Any ideas/thoughts from anyone on how to handle dissimilar base classes in a
  58. |'holder' class?
  59.  
  60. This is the primary legimate use of multiple inheritance.
  61.  
  62.     class Grandfathered : public Object, public ThirdPartyThing
  63.     {
  64.     ...
  65.     };
  66.  
  67. Watch out for member function name conflicts.
  68.  
  69. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  70. It's not the way that you say it    |
  71. when you do those things to me,        |    -Richard Hartman    
  72. it's more the way you really mean it    |    hartman@uLogic.COM
  73. when you tell me what will be.        |
  74.