next up previous contents
Next: vtkActorToPF Up: Patterns Used Previous: Mediator

Adapter

According to [7], the adapter pattern is used to adapt the interface of a class into another interface which clients expect. In order to be able to use Jim Costigan's widgets, they had to conform to the CaveTool abstraction. This was accomplished by implementing each cave tool in terms of an instance of one of Jim Costigan's widgets. For instance, one of the concrete subclasses of CaveTool is SliderTool. A SliderTool instantiates a slider object (a Jim Costigan widget). The SliderTool conforms to the CaveTool interface, but it delegates all the work to the slider object. The methods in SliderTool simply call methods in slider.

The desktop widgets also make use of the Adapter pattern. X/Motif widgets are "adapted" to the DesktopTool interface which is a subclass of Tool.

As a result, the developer can program for the most part using the Tool interface. This allows the code to be portable across the CAVE and the desktop. However, within the interface mediator, handles to either DesktopTools and CaveTools are kept. As mentioned in the last chapter, this is necessary in order to do some of the platform specific operations for these widgets.

  figure203
Figure 6.5: Partial diagram of Adapter pattern. The client (pjrWidget) expects a Tool object. The adapter (SliderTool) defines a SliderTool that conforms to the Tool interface and is implemented in terms of a slider object.



Paul John Rajlich
Mon May 4 16:53:57 CDT 1998