home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12360 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  2.6 KB

  1. 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
  2. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Downcasting (was: Re: run-time type checking)
  5. Message-ID: <1992Aug14.232322.7388@ucc.su.OZ.AU>
  6. Date: 14 Aug 92 23:23:22 GMT
  7. References: <9222518.29381@mulga.cs.mu.OZ.AU> <4820@holden.lulea.trab.se>
  8. Sender: news@ucc.su.OZ.AU
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. Lines: 43
  11. Nntp-Posting-Host: extro.ucc.su.oz.au
  12.  
  13. In article <4820@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
  14. >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  15. >:
  16. >:There are other ways than tagged pointers to make downcasting
  17. >:sound. One might be to declare the derived classes that you want
  18. >:to downcast to in the base class FROM which you want to downcast:
  19. >:    class Base { //....
  20. >:        operator Derived1*() =0;
  21. >:        operator Derived2*() =0;
  22. >:    };
  23. >:Now what does this do? Well, it preserved th open/closed principle
  24. >:and encapsulation and the explicit interfaces principle.
  25. >
  26. >What if someone using your classes decides to add a Derived3 class
  27. >to which downcasting should be possible?  He must modifiy your
  28. >class Base, for which he may not have source code.
  29. >
  30. >Does not (help) preserve the open/closed principle at all, IMHO.
  31.  
  32. You said it: he MUST reopen Base. Thats WHY it preserves the open/closed
  33. principle. If the Base is locked away (no source, in a library)
  34. it is CLOSED permanently and cannot be reopened, so you CANT
  35. get at the new derived3 class with a downcast using the above
  36. technique, because that would violate the closure of Base.
  37.  
  38. It is this very observation cojoined with the fact that with downcasting
  39. the restriction does not exist, that lead me to suspect that
  40. downcasting violates the open/closed principle.
  41.  
  42. It is precisely because you can extend (in the above sense) the base
  43. WITHOUT reopening it. Just adding a new derived class does NOT require
  44. this---it is polymorphism, it is using inheritance and it is
  45. in fact a consequence of the open/closed principle. Being able
  46. to add or not add and ARBITRARY derived class. A derived class
  47. you downcast to is not arbitrary, its not polymorphic but
  48. heteromorphic (one of a specific set of distinguished objects).
  49.  
  50.  
  51. -- 
  52. ;----------------------------------------------------------------------
  53.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  54.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  55. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  56.