home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!spool.mu.edu!agate!agate!matt
- From: matt@physics.berkeley.edu (Matt Austern)
- Newsgroups: comp.lang.c++
- Subject: Re: Need help implementic data structures of generic objects
- Date: 11 Dec 92 16:26:29
- Organization: Lawrence Berkeley Laboratory (Theoretical Physics Group)
- Lines: 34
- Message-ID: <MATT.92Dec11162629@physics.berkeley.edu>
- References: <1992Dec8.165230.2587@ucc.su.OZ.AU> <42186@sdcc12.ucsd.edu>
- <1992Dec10.114636.16861@ucc.su.OZ.AU>
- <1992Dec11.233253.27540@informix.com>
- Reply-To: matt@physics.berkeley.edu
- NNTP-Posting-Host: physics.berkeley.edu
- In-reply-to: cshaver@informix.com's message of 11 Dec 92 23:32:53 GMT
-
- In article <1992Dec11.233253.27540@informix.com> cshaver@informix.com (Craig Shaver) writes:
-
- > >>class Object {
- > >> /* ...etc... */
- > >>};
- > >
- > > Dont do this Smalltalk hack please. A queue of Objects is
- > >totally useless, since they are just Objects and not ever Widgets.
- >
- > YES! Do that elegant Smalltalk thing. Do not listen to C++ hacks and
- > bigots. Put a little thought into it and do something (re)useful.
-
- The problem is that in C++, as opposed to Smalltalk, this *isn't*
- terribly elegant. The question is: what can you do with an Object?
- If you put a Widget into a list of Objects, you can't call any of the
- Widget member functions; you can only call the Object member
- functions.
-
- You can, of course, access the Widget member functions by downcasting
- the Object* to a Widget*, but I would scarcely call that elegant.
- (Also, of course, you're deliberately violating the language's type
- checking, so you're opening yourself up to all sorts of fun bugs.) I
- would suggest that if your program makes heavy use of downcasting,
- then you are probably not using the best possible design.
-
- There probably are some programs for which Smalltalk is a better
- choice of language than C++. For those programs, the simple solution
- is just to use Smalltalk; as Dr. Stroustrup has pointed out, Smalltalk
- does a far better job of being Smalltalk than C++ ever will.
- --
- Matthew Austern Just keep yelling until you attract a
- (510) 644-2618 crowd, then a constituency, a movement, a
- austern@lbl.bitnet faction, an army! If you don't have any
- matt@physics.berkeley.edu solutions, become a part of the problem!
-