home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13104 < prev    next >
Encoding:
Internet Message Format  |  1992-08-31  |  2.8 KB

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