Broadcaster
Problem
Glue Code supports many-to-one interactions between components. How can one support one-to-many, and many-to-many (group-based) interactions between components?
Context
Scripted Components must often be interconnected in more general configurations than the one-to-one invocations supported by Glue Code.
Forces
- Components must be loosely coupled: they must rely on as few other components as possible.
- Components must be reusable: it must be possible to use them in as many situations involving as many other types of component as possible.
- Components must be interconnected, in general, in a many-to-many configuration.
Solution
Following the Observer pattern, implement a Scripted Component that "broadcasts" calls to its scripting interface to multiple "listener" components. The Broadcaster must provide operations through which multiple Glue Code scripts can be easily registered and removed and an operation that is called from Glue Code invoked by by another component and calls each of the registered scripts in turn, passing the arguments to the operation to each scripts.
Consequences
One or more "announcer" components can communicate to one or more "listener" components.
A component can be an "announcer" and a "listener" at the same time.
The program can treat a group of components as a single entity without needing to know the exact identities of the group members.
In many scripting languages and runtime libraries, a Broadcaster component can be completely generic, in that It can be written to handle any number of parameters of any type.
Known Uses
Tcl allows the programmer to register callbacks on variables that are invoked when the value of the variable is changed. This allows any variable to be used as a Broadcaster. Many widgets in the Tk user-interface toolkit use Traced Variables in this way.
ActiveX components for VisualBasic and other scripting languages on the Windows platform use "connection point" objects to manage event callbacks. A component has a connection point for each event it can generate. Other objects use the connection point to register interest in the event. The component enumerates the objects registered with the connection point and calls them when an event occurs.
Nat Pryce (np2@doc.ic.ac.uk).