Implementation

[Previous] [Next]

Depending on the system design, the Prototypical Object Factory design pattern can be implemented as an ActiveX EXE project, as I suggested in the "Scenario" section, or as an ActiveX DLL, as I alluded to in the third point of the "Ramifications" section.

Implementing the Prototypical Object Factory design pattern in an ActiveX EXE should be carried out as follows:

  1. Define the Prototype interface ClassModule.
  2. Set the Prototype's Instancing property value to PublicNotCreatable to permit clients of this component to only declare object variables of this type or define classes that implement this interface.
  3. Define an ObjectFactory ClassModule.
  4. Set the ObjectFactory's Instancing property value to MultiUse or SingleUse to allow clients to create instances of this class. (Refer to Chapter 3 of this book or to the Microsoft Visual Basic 6.0 Programmer's Guide for a complete explanation of the Instancing property values.)
  5. Define a default set of ClassModules that implement the Prototype interface.

There are two rather important points to keep in mind when implementing the Prototypical Object Factory design pattern in an ActiveX EXE. First, if zero downtime tolerance is in place, subsequent requirements to create new ClassModules should be defined in new ActiveX EXE component projects, as illustrated in Figure 9-1. Second, the object factory must be implemented as a Singleton design pattern (Chapter 10) to ensure that all objects are registered with the same object factory.

Frameworks in many cases are implemented as DLLs that are loaded into a client process. The client typically extends the functionality of the framework by either inheriting framework interfaces or by trapping framework events. By implementing the Prototypical Object Factory design pattern, the framework can permit the dynamic extension of framework behavior.

Let's assume the client was developed as a Visual Basic Standard EXE project. In the References dialog box, you select the appropriate framework ActiveX DLL. This will give the client access to all the framework's interfaces, classes, enumerated data types, and user-defined types, which you can easily navigate through using the Object Browser in the Visual Basic development environment. In the client code you could then do the following:

  1. Define ClassModules that implement the Prototype interface.
  2. Set up a Singleton reference to the framework's object factory.
  3. Create instances of the classes that support the Prototype interface and register these instances with the object factory using its registration method.

When operations are invoked in the framework that require the functionality defined in the Prototype interface, the behavior you defined in your ClassModules will be available.



Microsoft Visual Basic Design Patterns
Microsoft Visual Basic Design Patterns (Microsoft Professional Series)
ISBN: B00006L567
EAN: N/A
Year: 2000
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net