• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Interfaces and Static Methods

 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Any recommendations?

Thanks!

Pretty typical delegation setup for my app:




Example existing DAO method:

[ August 14, 2006: Message edited by: Carl Trusiak ]
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest you use a DAO Factory pattern, there are several discussed Here in the J2EE Blue Prints book.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
BWA HA HA HA HA HA HA! Tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic