home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cimshop!davidm
- From: davidm@consilium.com (David S. Masterson)
- Newsgroups: comp.lang.c++
- Subject: Re: Callbacks - C++ needs an extension?
- Message-ID: <DAVIDM.92Aug31105639@consilium.com>
- Date: 31 Aug 92 17:56:39 GMT
- References: <1992Aug28.165108.17479@isy.liu.se>
- <1992Aug29.161356.16729@genghis.borland.com> <1893@acf5.NYU.EDU>
- Sender: root@cimshop.UUCP
- Distribution: comp
- Organization: Consilium Inc., Mountain View, California
- Lines: 58
- In-reply-to: checker@acf5.NYU.EDU's message of 29 Aug 92 19:26:35 GMT
- X-Posting-Software: GNUS 3.13 [ NNTP-based News Reader for GNU Emacs ]
-
- >>>>> On 29 Aug 92 19:26:35 GMT, checker@acf5.NYU.EDU (checker) said:
-
- > There is a simple way of doing blind callbacks in a typesafe manner using an
- > intermediary class and a pure virtual function:
-
- > class callback
- > {
- > public:
- > virtual void CallBack( void ) = 0;
- > };
-
- > This is the interface class. An object that needs to call another
- > object back takes a reference to one of these:
-
- > class button
- > {
- > public:
- > button( callback &CalledWhenPushed, etc. );
- > };
-
- [...]
-
- > That's it. button knows absolutely nothing about who it is calling. The
- > method uses the virtual call mechanism so it is completely type safe. There
- > is no run time switching on message types, etc, and the method is easily
- > extended using templates and/or nested classes.
-
- > This technique is a typical use of the abstract interface/concrete
- > implementation idea. All of the grungy details are in the derived class, so
- > the folks using the base don't have to know about them.
-
- Interesting technique, but I have a few questions:
-
- 1. Could you make this work in the case of windowing systems that treat
- callbacks as C functions? Would it be a double callback (ie. callback to a C
- function that then calls the appropriate callback object)?
-
- 2. How does the windowing system pass data to the callback? With buttons,
- for instance, all that needs to be known is the action (buttonPush). With
- text widgets, though, the program will want to get at the data that is
- provided in the event. Do this technique advocate a "push" model (the window
- system sends data to the program) or a "pull" model (the program asks for the
- available data)?
-
- 3. Given a windowing system based on C, its likely that the information
- coming from the windowing system will not be C++ object oriented (ie. it won't
- follow a C++ inheritance model). How do you convert?
- --
- ====================================================================
- David Masterson Consilium, Inc.
- (415) 691-6311 640 Clyde Ct.
- davidm@consilium.com Mtn. View, CA 94043
- ====================================================================
- "Creative minds always have been known to survive any kind of bad training."
- -- Anna Freud
-
- Well, sometimes, anyway.
- -- Mark Brader, utzoo!sq!msb
-