Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Database access class design question

Thread view: 
Martin Gregorie - 10 Jun 2007 10:28 GMT
I'm currently writing a set of closely related programs which all run
against a fairly simple RDBMS schema. There's little or no overlap
between the operations they apply to the DB (one batch loads data,
another interactively retrieves it while the third weeds out
unwanted/old data).

Currently only the loader is complete and running. I've put all its SQL
operations into a single class, using a small set of public methods that
map well to the program's DB manipulation requirements. The DB functions
for the remaining programs are fairly disjoint so their SQL operations
could be encapsulated in separate classes apart from a few methods
(currently implemented as private) which are likely to be common to all
programs.

I can either split out the few common methods into a separate class
which is extended to provide separate database access classes for each
of the programs or I can build a single, large class that exposes all
the database access methods used by these programs. Polymorphism is
irrelevant: each program only needs a single instance of its database
access class.
- Which is the best of these approaches?
- Is there some better third way I should be using?

Currently I'm leaning toward the single database access class because
this is similar to the way large classes such as StringBuffer are
structured in the JDK class library.

All comments and suggestions are welcome.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Arne Vajhøj - 04 Jul 2007 04:37 GMT
> I'm currently writing a set of closely related programs which all run
> against a fairly simple RDBMS schema. There's little or no overlap
[quoted text clipped - 22 lines]
> this is similar to the way large classes such as StringBuffer are
> structured in the JDK class library.

I would go for a common base class and specific classes. If your
programs develop over time, then it should make code reuse easier.

Arne
Martin Gregorie - 04 Jul 2007 17:16 GMT
>> I'm currently writing a set of closely related programs which all run
>> against a fairly simple RDBMS schema. There's little or no overlap
[quoted text clipped - 25 lines]
> I would go for a common base class and specific classes. If your
> programs develop over time, then it should make code reuse easier.

Thanks, Arne.

This has sat on the ng for quite a while without getting any answers. In
the meantime I restructured my initial code as a (fairly minimal) base
class and a set of program-specific extensions after deciding that there
was less commonality than I originally thought.

Thanks for confirming that this is a sensible approach.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.