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