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: Const Inheritance
- Message-ID: <1992Nov8.030406.15468@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: <2762@devnull.mpd.tandem.com> <Bx970t.B72@cdsmn.mn.org>
- Date: Sun, 8 Nov 1992 03:04:06 GMT
- Lines: 43
-
- In article <Bx970t.B72@cdsmn.mn.org> wells@cdsmn.mn.org (Rich Wells) writes:
- >Duane Voth (duanev@devnull.mpd.tandem.com) wrote:
- >: frank@Cookie.secapl.com (Frank Adams) writes:
- >: >The idea comes from one of the standard examples of an inheritance
- >: >hierarchy: shapes. Assume we have a class Shape, with a subclass
- >: >Rectangle, and we want to add Square as a class. It seems logical that
- >: >Square should be a subclass of Rectangle.
- >
- >Let us not confuse "subset" with "subclass". "Subclass" is a concept
- >we use for implementation; it need not correspond directly to the
- >"subset" and "superset" concepts we may be modeling.
-
- Not my way of seeing it. Subclasses must be subsets, but that
- is not enough, mutators on elements of a subclass must yield valid
- member of the subclass, i.e. subclasses are subsets closed under
- mutation.
-
- >
- >So: although the set of squares is a subset of the set of rectangles,
- >it does not (necessarily) mean that the class "square" should be a
- >subset of class "rectangle". Inheritance can be used for both
- >genericity AND specialization. In this case, perhaps Square may be
- >the immediate subclass of Shape, with Rectangle a more generic
- >subclass of Square containing an extra field for the extra degree
- >of freedom.
-
- In other words, inheritance can be used for other than subclassing.
- In particular, inheritance can also be used for composition in a manner
- functionally equivalent to inclusion. This is always the case in toto
- if the base has no virtual functions, the base could always have
- just been included as a member, although you would have to
- export the functions out of it manually.
-
-
- In any case, in the C++ community the words 'derived class'
- and 'base class' are used where inheritance is concerned, and
- 'subclassing' should be reserved IMHO for a strict IsA relation.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-