home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!gatech!swrinde!mips!mips!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Newsgroups: comp.lang.c++
- Subject: Re: Downcasting (was: Re: run-time type checking)
- Message-ID: <1992Aug14.232322.7388@ucc.su.OZ.AU>
- Date: 14 Aug 92 23:23:22 GMT
- References: <9222518.29381@mulga.cs.mu.OZ.AU> <4820@holden.lulea.trab.se>
- Sender: news@ucc.su.OZ.AU
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- Lines: 43
- Nntp-Posting-Host: extro.ucc.su.oz.au
-
- In article <4820@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
- >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
- >:
- >:There are other ways than tagged pointers to make downcasting
- >:sound. One might be to declare the derived classes that you want
- >:to downcast to in the base class FROM which you want to downcast:
- >: class Base { //....
- >: operator Derived1*() =0;
- >: operator Derived2*() =0;
- >: };
- >:Now what does this do? Well, it preserved th open/closed principle
- >:and encapsulation and the explicit interfaces principle.
- >
- >What if someone using your classes decides to add a Derived3 class
- >to which downcasting should be possible? He must modifiy your
- >class Base, for which he may not have source code.
- >
- >Does not (help) preserve the open/closed principle at all, IMHO.
-
- You said it: he MUST reopen Base. Thats WHY it preserves the open/closed
- principle. If the Base is locked away (no source, in a library)
- it is CLOSED permanently and cannot be reopened, so you CANT
- get at the new derived3 class with a downcast using the above
- technique, because that would violate the closure of Base.
-
- It is this very observation cojoined with the fact that with downcasting
- the restriction does not exist, that lead me to suspect that
- downcasting violates the open/closed principle.
-
- It is precisely because you can extend (in the above sense) the base
- WITHOUT reopening it. Just adding a new derived class does NOT require
- this---it is polymorphism, it is using inheritance and it is
- in fact a consequence of the open/closed principle. Being able
- to add or not add and ARBITRARY derived class. A derived class
- you downcast to is not arbitrary, its not polymorphic but
- heteromorphic (one of a specific set of distinguished objects).
-
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-