In an ActiveX DLL project named Adapters (located in the Adapter directory on the companion CD), I have implemented fully the SMap collection described in Scenario A of this chapter, which is an Opaque Object Adapter design pattern. What
is a brief compilation of all
in the sample application. Please refer to the companion CD for the full source code.
Map, the interface expected by
, is an abstract interface that defines how objects of any type are stored in a collection. It maps a key of type String to the object's location in the collection. So instead of traversing through a collection for the object required, you use the object's key for easy and instant retrieval. Because Map is an abstract interface, I created a class module named Map. Then I changed its
property value to PublicNotCreatable, which means you will not be able to create instances of the Map type outside this project. You can declare object
of type Map without receiving an error, but you will not be able to use the keyword
function to create an instance. As the following code extract illustrates, the Map class module contains property and function definitions with no implementation (empty function bodies):
SMap (Adapter) is a concrete Map class that implements the interface defined by Map. Said another way, SMap is a type of Map. SMap also has the added functionality of maintaining the collection in sorted order by key, hence the
The important functionality contained in SMap is its maintenance of a private object variable that stores a reference to a Visual Basic Collection object. Most of the work necessary to maintain the sorted map collection is delegated to the Collection object via the reference stored in
. Notice that all the functions derived from the Map interface—except for
—delegate all work to the
This example clearly illustrates the major advantage of an Adapter design pattern, which is its ability to define a new type of object that makes effective use of existing system
You can use the AdapterTester project, located in the Adapter\AdapterTester subdirectory on the companion CD, to test the Adapters DLL.