home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:20087 comp.lang.c++:19780
- Newsgroups: comp.lang.c,comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: discriminated unions (Re: C/C++ Correctness (was: Re: C/C++ Speed))
- Message-ID: <1993Jan22.200303.23880@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <TMB.93Jan20160311@arolla.idiap.ch> <1993Jan20.184221.19003@netcom.com> <TMB.93Jan21014916@arolla.idiap.ch>
- Date: Fri, 22 Jan 1993 20:03:03 GMT
- Lines: 53
-
- In article <TMB.93Jan21014916@arolla.idiap.ch> tmb@idiap.ch writes:
- >
- >People who believe in purely OO design will argue that switching on
- >types will not occur in "well designed code".
-
- And in a statically typed, class based language
- like C++ these people would in my opinion be wrong.
-
- >But it does in practice, even in well-designed code.
-
- It is not just a hack, as your comment might be
- interpreted as suggesting.
-
- IMHO: there is a *fundamental* difference between
- vectoring (virtual functions) and indexing (switching).
- Neither can be correctly used in place of the other.
-
- The whole notion of a polymorphism in a static class
- based language rests on being able to CLOSE the base class,
- while at the same time leaving it open for ARBITRARY
- extension (leave it OPEN). Inheritance enables this.
-
- There is a restriction: the class must be
- closed yet left open for ARBITRARY extension. In otherwords,
- you can derive any classes you like from a base class.
-
- As such, the only thing you can rely on is the
- declared interface of the base class: then number
- of derived class is effectively infinite.
-
- On the other hand, with unions and type switching,
- there is always a FINITE number of classes. These classes
- are specifically known, and may have different interfaces.
-
- So the distinction is simple:
-
- Inheritance/virtual functions is used when
- a common interface supports arbitrary implementations.
-
- Unions/switching is used when there is a finite number
- of declared and disparate interfaces.
-
- Attempting to replace one of these mechanisms with the other
- is committing the gravest category error: claiming
- one can substitue for the other is just absurd.
-
- We need them both.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;------ SCIENTIFIC AND ENGINEERING SOFTWARE ---ph: 2 799 8223 --------
-