DAO Factory(ies)

All,

Ive implemented a classic DAO Factory. However, I want the DAOFactory to not require calling methods to indicate the type of factory to use, such as Oracle or MS SQL. I would like the DAOFactory to return a SQLFactory, OracleFactory, or XMLFactory based upon environmental setup. I also wish to take this one step further, where some storage items only can be certain types, such as xml files.

Currently, the DAOFactory is an abstract class, which is extended by each sub factory, and therefore each sub factory must override each DAOFactory method.

Therefore, if xyz were an XML file, and not a table, methods would still have to be coded in the database factories. I need to insert a layer that returns different DAOFactory(ies), such as DB, XLM, etc, based upon environmental setup.

I was thinking creating a Singleton and calling it DAOFactory. It would get/hold environmental variables for storage items, types, etc. It would then return a current DAOFactory, implemented in the traditional pattern, as either DAOFactoryDB or DAOFactoryXML.

Also, with the DAOFactoryDB, it would could tell it which DB vendor type to return, removing that burden from the originating class wanting the DAO. The other benefit is if items move between storage types in the future, the calling objects would not need to be updated (e.g. xml file moved to a table or visa versa).

Im curious if anyone has done anything like this before, such as inserting another abstraction layer above the factory. Im also interested in comments, criticisms, suggestions, etc.

Thanks

bRi

[1626 byte] By [BrianLedsworth] at [2007-9-26 19:24:45]
# 1
Looks like what you want is a Factory of factories, why dont you create a factory class which looks up the variables and creates a specific factory DB,XML etc..
sharatJ at 2007-7-3 11:49:44 > top of Java-index,Other Topics,Patterns & OO Design...