Wiki Home

VFEExtending The Abstract Factory


Namespace: VFP
VFE Tip: Extending the Abstract Factory
Version: VFE 6.0

Overview
The VFE Framework uses an Abstract Factory to instantiate instances of classes within a VFE application. The abstract factory is a data driven factory that determines the class to be used based on a description.

The Abstract Factory is accessible through the application object's oFactory property. The table used by the abstract factory is named classes. The classes table resides in the VFEFRAME\DATA directory.

In VFE SP1 an intermediate factory was introduced. The intermediate factory looks at the iClasses table in the iLibs directory. When a request is sent to the factory the iFactory is checked first and if a matching description is not found, then the cFactory (framework level) factory is checked. This change allows to make changes to the iClasses table without worrying if F1Technologies updates the classes table in an update.

Extending the Factory
The classes table used by the factory is considered part of the VFE Framework and therefore VFE users should avoid changing the classes table to eliminate conflicts with future updates.

Nearly all of the classes that are instantiated via the factory are instantiated from the intermediate layer. If you're considering changing the factory because you wish to change the behavior of a class that's instantiated via the factory, first consider changing the class in the intermediate layer.

Creating your own factory
Often it is desirable to add application specific entries to the factory. Obviously, this cannot be done at the framework or intermediate layer because the application specific entries would take effect in all of your VFE applications. Enhancements made in SP1 make it possible to chain factories together, which makes it very easy to implement an application specific factory. The steps below describe how to make an application specific factory.

1. Copy the structure (including indexes) of iClasses.DBF to aClasses.dbf into your applications meta data directory.Use iLibs\iClasses.DBF;Copy Structure to metadata\aClasses with cdx

2. Create a subclass of iFactory called aFactory in your applications libs directory and add the class library to the project. (You can use the new class wizard under other objects in the VFE classes page to do all of this.) Create Class aFactory of libs\aFactory as iFactory from ilibs\iFactory(leave open for next step.)

3. Open the aFactory class and set its cNextFactory property to iFactory and its cTable property to aClasses. (Set the Include file for the class to d:\vfe7\vfeframe\include\vfe.h )

4. Open the application class and set its cFactoryClass property to aFactory.

Once you've done this you now have an application specific factory. You can use the application specific factory to override defaults established at the framework or intermediate layer as well as to specify classes to use in given situations that are specific to the application.
Using the New Connection Manager to Share Remote Connections

1. Create an application specific factory. (see above)

2. Add a record to the factory with a description of Connection Manager and a class of iConnectionManager. Insert into metadata\aClasses ( cDescript, cClass ) values ( "Connection Manager", "iConnectionManager" )

3. Create an application specific subclass of a connection. The class that is used will vary depending on you data source. For SQL Server use iSQLServerConnection. Create Class aSQLServerConnection of aapp as iSQLServerConnection from iLibs\iData

4. Set the necessary properties of the connection class in order to connect to the data source.

5. Add another record to the application specific factory with a description of Application Connection and the class from step 3. Insert into metadata\aClasses ( cDescript, cClass ) values ( "Application Connection", "aSQLServerConnection" )

Category Visual FoxExpress, Category Visual FoxExpress Tips And Tricks, Category Visual FoxExpress Faq
( Topic last updated: 2004.03.01 10:38:38 AM )