home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20087 < prev    next >
Encoding:
Internet Message Format  |  1993-01-23  |  2.5 KB

  1. Xref: sparky comp.lang.c:20087 comp.lang.c++:19780
  2. Newsgroups: comp.lang.c,comp.lang.c++
  3. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  4. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  5. Subject: Re: discriminated unions (Re: C/C++ Correctness (was: Re: C/C++ Speed))
  6. Message-ID: <1993Jan22.200303.23880@ucc.su.OZ.AU>
  7. Sender: news@ucc.su.OZ.AU
  8. Nntp-Posting-Host: extro.ucc.su.oz.au
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. References: <TMB.93Jan20160311@arolla.idiap.ch> <1993Jan20.184221.19003@netcom.com> <TMB.93Jan21014916@arolla.idiap.ch>
  11. Date: Fri, 22 Jan 1993 20:03:03 GMT
  12. Lines: 53
  13.  
  14. In article <TMB.93Jan21014916@arolla.idiap.ch> tmb@idiap.ch writes:
  15. >
  16. >People who believe in purely OO design will argue that switching on
  17. >types will not occur in "well designed code". 
  18.  
  19.     And in a statically typed, class based language
  20. like C++ these people would in my opinion be wrong.
  21.  
  22. >But it does in practice, even in well-designed code.  
  23.  
  24.     It is not just a hack, as your comment might be 
  25. interpreted as suggesting.
  26.  
  27.     IMHO: there is a *fundamental* difference between
  28. vectoring (virtual functions) and indexing (switching).
  29. Neither can be correctly used in place of the other.
  30.  
  31.     The whole notion of a polymorphism in a static class
  32. based language rests on being able to CLOSE the base class,
  33. while at the same time leaving it open for ARBITRARY
  34. extension (leave it OPEN). Inheritance enables this.
  35.  
  36.     There is a restriction: the class must be
  37. closed yet left open for ARBITRARY extension. In otherwords,
  38. you can derive any classes you like from a base class.
  39.  
  40.     As such, the only thing you can rely on is the
  41. declared interface of the base class: then number
  42. of derived class is effectively infinite.
  43.  
  44.     On the other hand, with unions and type switching,
  45. there is always a FINITE number of classes. These classes
  46. are specifically known, and may have different interfaces.
  47.  
  48.     So the distinction is simple:
  49.  
  50.     Inheritance/virtual functions is used when
  51.     a common interface supports arbitrary implementations.
  52.  
  53.     Unions/switching is used when there is a finite number
  54.     of declared and disparate interfaces.
  55.  
  56. Attempting to replace one of these mechanisms with the other
  57. is committing the gravest category error: claiming
  58. one can substitue for the other is just absurd.
  59.  
  60. We need them both.
  61.  
  62. -- 
  63. ;----------------------------------------------------------------------
  64.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  65.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  66. ;------ SCIENTIFIC AND ENGINEERING SOFTWARE ---ph:  2 799 8223 --------
  67.