Component Glue

Please see the following link for the most updated version of the ComponentGlue pattern: This is the PLoP'99 version of this pattern. A package of 39 Pdfs from the conference is available in a single download

Old version in canonical form included below.

Context

You are building a framework into which components can be plugged. You have defined AbstractInteractions between components. Some components need to communicate but play roles in different interactions, or, although they have compatible roles, they have slightly different type signatures.

Problem

How can users easily plug together incompatible components?

Forces

Solution

In Java, anonymous inner classes that implement interfaces of AbstractInteractions can act as ComponentGlue.

In C++, template classes can be created for each interface of the framework's AbstractInteractions that delegate calls through member function pointers. Framework users can instantiate such templates to create ComponentGlue.

Scripting languages can be used to provide ComponentGlue. Components can interpret scripts rather than directly communicating with other components. The scripts can adapt parameters from one interface to another. See the Glue Code and pattern at http://www-dse.doc.ic.ac.uk/~np2/patterns/scripting for a more detailed description.

Resulting Context

It is easier to build a system from components if one doesn't have to implement many new components whose only job is to adapt invocations between other components. The ComponentGlue adaptors do not themselves have to be components: they do not themselves plug into the framework but instead facilitate the plugging of components into the framework.

The architectural view of the system (that part of the system where ThirdPartyBinding's are specified) emphasises only those components that are performing application tasks (the "functional" components), and deemphasises those that are performing communication and interface adaption tasks.

Conversely, type coercions performed within ComponentGlue are not so visible at the architectural level. This can hide dangerous bugs. The ArianeFive disaster is an example of a bug caused by a type coercion that was valid in the software for the Ariane 4 but was invalid when other parts of the system were modified for the Ariane 5.

Known Uses

JavaBeans development tools generate anonymous inner classes to act as glue between components, routing events announced by one component to the method(s) of another component that can handle the events.

Tcl/Tk components use Tcl scripts as glue to tie the components into an application. Components evaluate scripts in the Tcl interpreter to announce events. The interpreter therefore acts as a Mediator between components, and scripts act as application-specific strategies used to parameterise components.

SmalltalkLanguage, RubyLanguage, SchemeLanguage and others reify lexical blocks, that are very convenient for defining glue between components.

NatPryce has written a user interface framework in C++ in which user-interface events are announced through abstract interfaces. Template classes that hold object and member-function pointers are used to route event announcements to methods of objects that can handle the events.

Example

Related Patterns

ComponentGlue objects act as Adapters between incompatible interfaces. They can also be considered as Strategies, parameterising the behaviour of the components that communicate through them.

If ComponentGlue is implemented using scripting, the script interpreter (or script-level object, such as a VisualBasic form) acts as a Mediator between components and the scripts used to react to a component's events can be thought of as Strategies modifying the behaviour of that component.

If components support InterfaceDiscovery and scripting, scripts can be generated automatically from the interface signatures of the components between which they are acting as ComponentGlue. This is termed a BootstrapScript at http://www-dse.doc.ic.ac.uk/~np2/patterns/scripting.

On the other hand, if components SplitDesignTimeAndRunTime, ComponentGlue must be generated during system construction.

Gluing components together may require GoingThroughCustoms.


CategoryInterface ComponentDesignPatterns CategoryPattern
EditText of this page (last edited May 6, 2004)
FindPage by browsing or searching

This page mirrored in ComponentDesignPatterns as of April 29, 2006