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