I have an app that consist of a core application and an application instance. The db connection, queries, etc. All reside in the application instance so the system can work with any db they want.
Recently, I tried to connect to 'new' MS SQL Server 2005 and found I had to tweak my DAO class a little to work with it.
Up until this point, my DAO class has been universal for all dbs. Now I need to pay attention to what db is being used and utilize the appropriate DAO class. note: you define what db you are using in a config file.
The rest of my app uses delegation to handle the differences from app to app, so my natural inclination is to use the same appraoch for the DAO class problem, since it fits (almost...).
The problem is all of my DAO methods are static and I can't use static methods in an interface.
Pretty typical delegation setup for my app:
Example existing DAO method:
[ August 14, 2006: Message edited by: Carl Trusiak ]
I had to retrofit a class with all static methods for polymorphism and wound up with an interface with non-static methods that match the static methods plus a number of implementations of the interface. Then you might have:
So each static method just passes the call through to the current implementation.
BTW: Those static variables will make you crazy when it comes time to multi-thread. Think of ways to avoid them. For example, just
For grins, look into the Spring JDBC framework. It does some cool stuff and might save you a lot of work writing your own. [ August 14, 2006: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi