Abstract Constructor [Lan96]
A View Factory provides a uniform interface to creating Hierarchical Views. You present a key to the factory and get a view in return.
You are using an object-oriented language for the implementation of the Relational Database Access Layer Framework. You want to implement a single factory for all objects derived from the View abstract class. This ViewFactory should work together with the View Cache.
How do you implement a single factory for all View subclasses that determines the right subtype from the given database key?
Flexibility: The languages we are using for implementing the Database Access layer will usually not support RTTI[1]. However the View base class should not need to be changed when a new ConcreteView class is added.
Exception Behavior: A View Factory also has to take into account that client code needs different exception behavior for Views that have to be activated from the database (read() followed by update()) and Views that do not yet exist in the database (insert()).
Implement an Abstract Factory [GOF95] using an Abstract Constructor [Lan96] and shield it with an interface that distinguishes between new objects and objects that are activated from the database.
The ViewFactory is responsible for creating new Views and for activating existing ones. It works together with the ViewCache as explained in the View Cache pattern. The basic interface needed here is given by the following class declaration:
class ViewFactory { public: static View * createView ( ViewKey aKey ); static View * getView (ViewKey aKey); }; |
When implementing a View Factory you may use the following patterns. The Abstract Constructor pattern [Lan96] contains a detailed description of how to implement a ViewFactory. Usually Prototypes [GOF95] are used to trick statically typed languages. As stated above in the View Cache pattern, pointers returned by the getView() method can be made safer using Smart Pointers [Mey96] or the Counted Pointers Idiom [Cop92].
The Abstract Interface [Col96] is a special form of an Abstract Constructor [Lan96] or Abstract Factory [GOF95] used for decoupling purposes. Much of the deeper discussion about this pattern may be found there.
sd&ms HYPO project contains a View Factory [Kel+96a].
The equivalent of a View Factory for non-object-oriented-languages is some form of memory allocation for Views. This is especially tricky for transaction systems like CICS or IMS/TM. Refer e.g. to sd&ms Thyssen project and various other host projects if you are looking for more details.