Database access class design question

M

Martin Gregorie

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.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Martin said:
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.

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
 
M

Martin Gregorie

Arne said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

MVC design questions 25
Design Question 26
Design Question 37
Design Questions about static factory classes 84
Design Question 4
Design question 1
web access to configuration database 0
Class design for DB code 5

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top