home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!sdl!adk
- From: adk@Warren.MENTORG.COM (Ajay Kamdar)
- Subject: Re: Downcasting (was: Re: run-time type checking)
- Message-ID: <1992Aug12.211716.7975@Warren.MENTORG.COM>
- Keywords: polymorphism, RTTI, downcasts.
- Organization: Mentor Graphics Corp. - IC Group
- References: <1992Aug8.152913.20167@mole-end.matawan.nj.us> <1992Aug9.221309.15259@ucc.su.OZ.AU> <9222518.29381@mulga.cs.mu.OZ.AU>
- Date: Wed, 12 Aug 1992 21:17:16 GMT
- Lines: 53
-
- In article <9222518.29381@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) 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;
- >> };
- >>
- >>or with a special syntax:
- >>
- >> class Base {
- >> ..
- >> downcastable Derived1, Derived2;
- >> };
- >>
- >>Now what does this do? Well, it preserved th open/closed principle
- >>and encapsulation and the explicit interfaces principle.
- >
- >This is a good idea.
- >In particular, it seems that this technique much reduces the attraction of
- >the current proposal to allow downcasting, because users can achieve virtually
- >the same effect themselves - they just have to make the interface explicit.
- >
-
- I haven't been following this debate much, so I may be missing the point
- here, but it pains me to see people get really excited about this idea.
- I don't care what principles this approach obeys, the very fact that it
- requires the base class to know about its derived classes and requires the
- base class to be modified every time a new derived class is added makes this
- approach dead in the water as far as I am concerned. Making the Derived?*
- functions pure virtuals in the base class also forces each derived class to
- know about its sibling classes. No good. The current proposal to allow
- downcasting (I suppose that refers to the proposal by Bjarne Stroustrup and
- Dmitry Lenkov) is much superior to this approach. I will take that
- approach (provided that proposal gets accepted) any time over this old hack.
-
- Now that I have had my 2 cents on this issue, I relinquish the thread back
- to the regulars.
-
- Cheers,
-
- - Ajay
-
- --
- I speak for none but myself.
-
- Ajay Kamdar Email : ajay_kamdar@mentorg.com
- Mentor Graphics, IC Group (Warren, NJ) Phone : (908) 580-0102
-