home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Need help implementic data structures of generic objects
- Message-ID: <1992Dec19.192259.15137@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <724476558snx@trmphrst.demon.co.uk>
- Date: Sat, 19 Dec 1992 19:22:59 GMT
- Lines: 43
-
- In article <724476558snx@trmphrst.demon.co.uk> nikki@trmphrst.demon.co.uk writes:
- >In article <1992Dec13.002551.778@informix.com> cshaver@informix.com (Craig Shaver) writes:
- >
- >> This group seems to be biased against inheritance techniques in all cases.
- >
- >No, this group merely states that heterogeneous collections (and certain
- >other things) are difficult to implement in statically typed languages
- >like C++, because they are incompatible with static typing.
-
- Heterogeneity has nothing to do with inheritance.
- It is perfectly feasible and only mildly naughty to have collections
- of objects selected from a finite set of totally different
- predeclared classes.
-
- The mechanism for this already exists, it is the union.
-
- union U {A a; B b; C c; };
- U u[20]; // heterogenous collection
-
- [ ... ]
- >
- >This is the major problem with such systems - you end up with hundreds of
- >virtual functions in the base Object, most of which will not be used
- >(indeed, have no meaning) in a particular derived class. It can work, but
- >it is not elegant C++.
-
- Actually, it CANNOT work without downcasting and RTTI because
- the open/closed principle requires that it be possible to CLOSE off
- the class 'Object' once and for all.
-
- >
- >And as for inheritance, in C++ it is for expressing an "is-a"
- >relationship. Templates are for expressing genericity.
-
- It can and is (mis-, over-, ab-) used for very much more than
- this in C++, in particular, it is used as a convenient form of
- composition (inclusion) and also for convenient reuse.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-