home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:20075 comp.object:5110
- Path: sparky!uunet!crdgw1!rpi!uwm.edu!spool.mu.edu!agate!doc.ic.ac.uk!pipex!demon!trmphrst.demon.co.uk!nikki
- From: nikki@trmphrst.demon.co.uk (Nikki Locke)
- Newsgroups: comp.lang.c++,comp.object
- Subject: Re: HELP : Array of objects of diff classes ??
- Message-ID: <728016608snx@trmphrst.demon.co.uk>
- Date: 25 Jan 93 19:50:08 GMT
- References: <mcampbel.727881449@eola.cs.ucf.edu> <1jdgecINNp06@aurora.engr.LaTech.edu> <1993Jan19.112059.2882@ucc.su.OZ.AU>
- Sender: usenet@demon.co.uk
- Reply-To: nikki@trmphrst.demon.co.uk
- Followup-To: comp.lang.c++
- Organization: Trumphurst Ltd.
- Lines: 49
- X-Mailer: cppnews $Revision: 1.31 $
-
- > >In article <1993Jan19.112059.2882@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- answers a question on how to create and use heterogeneous collections,
- specifically a Holder which can contain PENCILs, PENs & ERASERs.
-
- MAX>I assume that it reasonable to allow Holder to hold any one of these objects
- MAX>because there is some similarity between these objects. e.g., they are all
- MAX>drawing tools or whatever. This concept of similarity should be captured by
- MAX>classifiying each of these item classes as subclasses (or specializations) of
- MAX>the common class (e.g., drawing_object - which may be abstract). Then, the
- MAX>Holder class simply has to be declared to be able to hold objects of type
- MAX>drawing_object. Then, any instance of PENCIL, PEN, ERASER and any other class
- MAX>derived from drawing_object cam be held by a Holder instance. Aggregates can
- MAX>hold heterogeneous collections etc.
-
- In article <mcampbel.727881449@eola.cs.ucf.edu> mcampbel@cs.ucf.edu (Mike Campbell ) writes:
- > 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?")
-
- So miltiply derive from the vendors class and from a common base class of
- your own.
-
- > 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.
-
- Which just goes to show how badly designed Borlands class library is !
- [ fx: Flameproof shields UP :-]
-
- > Any ideas/thoughts from anyone on how to handle dissimilar base classes in a
- > 'holder' class?
-
- Re-think your design - you almost certainly don't need heterogenous
- collections.
-
- If you really _do_ need them, then either ...
-
- 1) Use a different language.
- 2) Wait for run-time type identification to arrive in C++
- 3) Write your own RTTI (like Borland did).
-
- --
- Nikki Locke,Trumphurst Ltd.(PC and Unix consultancy) nikki@trmphrst.demon.co.uk
- trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.
-