home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:20013 comp.object:5087
- Path: sparky!uunet!charon.amdahl.com!netcomsv!netcomsv!ulogic!hartman
- From: hartman@ulogic.UUCP (Richard M. Hartman)
- Newsgroups: comp.lang.c++,comp.object
- Subject: Re: HELP : Array of objects of diff classes ??
- Message-ID: <927@ulogic.UUCP>
- Date: 27 Jan 93 19:06:26 GMT
- References: <1993Jan19.112059.2882@ucc.su.OZ.AU>> <CAMPBELL.93Jan22132319@analysis.src.honeywell.com> <mcampbel.727881449@eola.cs.ucf.edu>
- Followup-To: comp.lang.c++
- Organization: negligable
- Lines: 61
-
- In article <mcampbel.727881449@eola.cs.ucf.edu> mcampbel@cs.ucf.edu (Mike Campbell ) writes:
- |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?
-
- This is the primary legimate use of multiple inheritance.
-
- class Grandfathered : public Object, public ThirdPartyThing
- {
- ...
- };
-
- Watch out for member function name conflicts.
-
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- It's not the way that you say it |
- when you do those things to me, | -Richard Hartman
- it's more the way you really mean it | hartman@uLogic.COM
- when you tell me what will be. |
-