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

  1. Xref: sparky comp.lang.c++:19825 comp.object:5034
  2. Newsgroups: comp.lang.c++,comp.object
  3. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!cs.ucf.edu!mcampbel
  4. From: mcampbel@cs.ucf.edu (Mike Campbell )
  5. Subject: Re: HELP : Array of objects of diff classes ??
  6. Message-ID: <mcampbel.727881449@eola.cs.ucf.edu>
  7. Sender: news@cs.ucf.edu (News system)
  8. Organization: University of Central Florida
  9. References: <1jdgecINNp06@aurora.engr.LaTech.edu>     <1993Jan19.112059.2882@ucc.su.OZ.AU> <CAMPBELL.93Jan22132319@analysis.src.honeywell.com>
  10. Date: Sun, 24 Jan 1993 13:17:29 GMT
  11. Lines: 47
  12.  
  13. campbell@src.honeywell.com (Terry Campbell) writes:
  14.  
  15.  
  16. >In article <1993Jan19.112059.2882@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  17.  
  18. >>Dear Everybody,
  19. >>
  20. >>
  21. >>    I have a problem related to programming in an object oriented fashion.
  22. >>    Here`s the problem description :
  23. >>        There is an object class called Holder. The object holder can hold various
  24. >>        things : Pencils, Pens, Erasers etc. I`ve declared different classes for
  25. >>        these things ( class PENCIL, class PEN, class ERASER etc. ). 
  26. >>
  27. >>        The user of this program will choose at the runtime what objects to put
  28. >>        in the holder. The problem is how do i store this information (i.e the
  29. >>        contents ) in class HOLDER. I cannot create a single array of objects
  30. >>        because each object is of different class.
  31. >>    
  32.  
  33. >I assume that it reasonable to allow Holder to hold any one of these objects
  34. >because there is some similarity between these objects.  e.g., they are all
  35. >drawing tools or whatever.  This concept of similarity should be captured by
  36. >classifiying each of these item classes as subclasses (or specializations) of
  37. >the common class (e.g., drawing_object - which may be abstract).  Then, the
  38. >Holder class simply has to be declared to be able to hold objects of type
  39. >drawing_object.  Then, any instance of PENCIL, PEN, ERASER and any other class
  40. >derived from drawing_object cam be held by a Holder instance.  Aggregates can
  41. >hold heterogeneous collections etc.
  42.  
  43. I've been following this thread with some interest, and I find your reply 
  44. interesting.  
  45.  
  46. I agree with your analysis of the problem re: subclasses, however, what if
  47. you buy/purchase/steal classes from multiple vendors/coworkers/victims ?
  48. They necessarily will not have a common base class.  (Or is this correctly
  49. deemed "superclass?")
  50.  
  51. Borland does this - they have a common base class, "Object", as I recall, and
  52. all of the storage classes can hold 'objects'.  This allows the storage 
  53. classes to hold just about anything in their provided class library, as every-
  54. thing is derived from the 'object' class.
  55.  
  56. Any ideas/thoughts from anyone on how to handle dissimilar base classes in a
  57. 'holder' class?
  58.  
  59.  
  60.