Download 1 Introduction

Transcript
As mentioned earlier in most broadcasting implementations the object sending the message must send its
message multiple times, to every object receiving the message. It would be nice if the object sending the
message just had to send it once.
3.2 Broadcasting Messages Using a Handler Class
It is easy to see that the role handler facility, mentioned earlier, makes it possible for one object to broadcast a message to many receivers, if the semantics of the role handling is slightly changed. Instead of passing service requests from a sender to a receiver it has to be changed to pass messages from one sender to all
objects interested in the message. This is easily done, by first changing the names of the concerned classes
to more appropriate names and then by allowing many objects to be referred to by the same object managed
by the message handler. If a message handler is used, that handles the messages that shall be broadcast, the
object sending the message will only have to send its message once. All they do is send the message to a
message object. In the message object some sort of list are maintained that contains references to all the
objects interested in receiving the broadcasted message.
MessageHandler
Handles
Class
Offers
Message
Receiver
Class
Figure 9. The Broadcasting class structure
Every object that has a message that it wants to broadcast notifies the message handler, which in turn puts it
in the list of available messages. And all objects interested in receiving a broadcast notifies it by contacting
the message handler. They are then put in the list of references maintained by that particular message
object.
3.2.1 Different Type of Receivers
If the objects receiving a broadcasted message should be of different (class) types, and not are in the same
inheritance hierarchy, the Receiver class will have to be sub classed. One sub class per inheritance hierarchy.
3.2.2 Hooking the Message to the Receivers
There is a slight risk to difficulties due to that the objects receiving the broadcasted message might not
know how the message will look like. They must in some way conform to the message sent and have
knowledge of what arguments to expect. This is probably best realized by using a proxy object.
3.2.3 The Answer Expected
The problem of how to receive the answer expected has also to be solved. Due to the fact that the objects
receiving the broadcasted message will not have any knowledge of each other, they might overwrite each
10