home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12343 < prev    next >
Encoding:
Text File  |  1992-08-14  |  2.4 KB  |  65 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!sdl!adk
  3. From: adk@Warren.MENTORG.COM (Ajay Kamdar)
  4. Subject: Re: Downcasting (was: Re: run-time type checking)
  5. Message-ID: <1992Aug12.211716.7975@Warren.MENTORG.COM>
  6. Keywords: polymorphism, RTTI, downcasts.
  7. Organization: Mentor Graphics Corp. - IC Group
  8. References: <1992Aug8.152913.20167@mole-end.matawan.nj.us> <1992Aug9.221309.15259@ucc.su.OZ.AU> <9222518.29381@mulga.cs.mu.OZ.AU>
  9. Date: Wed, 12 Aug 1992 21:17:16 GMT
  10. Lines: 53
  11.  
  12. In article <9222518.29381@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  13. >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  14. >
  15. >>There are other ways than tagged pointers to make downcasting
  16. >>sound. One might be to declare the derived classes that you want
  17. >>to downcast to in the base class FROM which you want to downcast:
  18. >>
  19. >>    class Base {
  20. >>        ....
  21. >>        operator Derived1*() =0;
  22. >>        operator Derived2*() =0;
  23. >>    };
  24. >>
  25. >>or with a special syntax:
  26. >>
  27. >>     class Base {
  28. >>        ..
  29. >>        downcastable Derived1, Derived2;
  30. >>    };
  31. >>
  32. >>Now what does this do? Well, it preserved th open/closed principle
  33. >>and encapsulation and the explicit interfaces principle.
  34. >
  35. >This is a good idea.
  36. >In particular, it seems that this technique much reduces the attraction of
  37. >the current proposal to allow downcasting, because users can achieve virtually
  38. >the same effect themselves - they just have to make the interface explicit.
  39. >
  40.  
  41. I haven't been following this debate much, so I may be missing the point
  42. here, but it pains me to see people get really excited about this idea.
  43. I don't care what principles this approach obeys, the very fact that it
  44. requires the base class to know about its derived classes and requires the
  45. base class to be modified every time a new derived class is added makes this
  46. approach dead in the water as far as I am concerned. Making the Derived?*
  47. functions pure virtuals in the base class also forces each derived class to
  48. know about its sibling classes. No good. The current proposal to allow
  49. downcasting (I suppose that refers to the proposal by Bjarne Stroustrup and
  50. Dmitry Lenkov) is much superior to this approach. I will take that
  51. approach (provided that proposal gets accepted) any time over this old hack.
  52.  
  53. Now that I have had my 2 cents on this issue, I relinquish the thread back
  54. to the regulars.
  55.  
  56. Cheers,
  57.  
  58. - Ajay
  59.  
  60. -- 
  61. I speak for none but myself.
  62.  
  63. Ajay Kamdar                               Email : ajay_kamdar@mentorg.com
  64. Mentor Graphics, IC Group (Warren, NJ)    Phone : (908) 580-0102
  65.