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

  1. Xref: sparky comp.lang.c++:19925 comp.std.c++:2123
  2. Newsgroups: comp.lang.c++,comp.std.c++
  3. Path: sparky!uunet!rational.com!stripe!rmartin
  4. From: rmartin@stripe.Rational.COM (Bob Martin)
  5. Subject: Re: Callbacks -- suggested approaches??
  6. Message-ID: <rmartin.728090477@stripe>
  7. Sender: news@rational.com
  8. Organization: Rational
  9. References: <DAVIDM.93Jan25171343@consilium.com>
  10. Date: Tue, 26 Jan 1993 23:21:17 GMT
  11. Lines: 50
  12.  
  13. davidm@consilium.com (David S. Masterson) writes:
  14.  
  15. |Processes communicate by passing
  16. |Message objects that contains any necessary data.  The receiving Process
  17. |object looks into the incoming Message, determines its type (a number), and
  18. |dispatches it (via table lookup) to a callback function on the Process object
  19. |that has been previously registered for that type of Message.
  20.  
  21. Passing messages between processes is always a challenge, especially
  22. when what you really want to do is pass messages between two objects
  23. which happen to live in different processes.  It would be very nice if
  24. the sending and receiving objects did not know that the message was
  25. crossing a process boundary.  Below is described a technique for
  26. achieving this.
  27.  
  28. Given that class A wants to send the message X to class B.  (This is the
  29. OO concept of a message.  I will refer to the data exchanged between
  30. processes as a packet.)  
  31.  
  32.     A::f(B* theB)
  33.     {
  34.       theB->X();
  35.     }
  36.  
  37. Unfortunately, theB lives in another process.  No problem.  Create an
  38. abstract class called AbstractB.  It contains a set of pure virtual
  39. functions defining all the messages that B can receive.  B will
  40. inherit from AbstractB.  So will another class called BSurrogate.
  41. BSurrogate knows which process the real B object lives in and knows
  42. how to convert the message into a packet and ship it to that process.
  43. The packet will contain all the arguments to X, an identifier denoting
  44. that it represents an X message and the identifier of the B object to
  45. which the message should be sent.
  46.  
  47. When the process receives the it looks up the name of the object in a
  48. dictionary.  The dictionary associates the name with a derivative of
  49. the class Reciever.  BReceiver is derived from Receiver, and knows how
  50. to unpack the X packet.  It also knows where the B object is (Probably
  51. it contains a pointer to it), so it unpacks all the arguments and then
  52. sends the message to its B object.  
  53.  
  54. Return values can be passed back by the same route by simply having
  55. the Surrogate add a return address onto the packet.
  56.  
  57.  
  58. --
  59. Robert Martin       | Design Consulting    | Training courses offered:
  60. R. C. M. Consulting | rmartin@rational.com |  Object Oriented Analysis
  61. 2080 Cranbrook Rd.  | Tel: (708) 918-1004  |  Object Oriented Design
  62. Green Oaks, Il 60048| Fax: (708) 918-1023  |  C++
  63.