Re: looking for opinons regarding best practices (jdbc, resultsets,
and servlet design)
Arne Vajh?j wrote:
I think there are a couple of problems with your approach:
* JDBC calls in your servlet (servlet is controller layer,
JDBC calls belong in data access layer)
* the usage of out.println (servlet is controller layer,
output generation belong in presentation layer)
Chris Uppal wrote:
But you aren't addressing the question: you are /assuming/ that the
architecture you descibe represents best practice; the OP wants to know
/whether/ it is (always) best practise, and presumably why.
Good point. What Arne proposes is nearly always a best practice (with
vanishingly few exceptions) because it separates concerns and minimizes the
interactions that bugs might have with each other. It also facilitates
maintenance over time. (Remember that by far the largest part of an
application's lifecycle is after it goes to production.)
For what little it's worth: I have a distrust of the complexities implied by
the commonly advocated architecture, with all its layers and TLAs, and would
generally take the approach that if a simpler approach /does/ work (and can be
expected to continue to work as the application evolves) then that is to be
preferred.
But it cannot be expected to work as the application evolves, that's why the
layers are there.
These layers are far less important in small, simple applications. Perhaps it
is enough to use JSTL "sql" tags in your JSPs, but as soon as an application
grows to more than just "one-off" size that begins to break down. Interactions
between program aspects get much, even geometrically larger and it gets
concomitantly harder to track down where things need to change.
The layers keep things simpler for large-enough projects. Most projects in my
own experience for which there was a paycheck were large enough. Furthermore,
I find that dividing things into layers makes things simpler *even for smaller
projects*. Since I have the pattern well established in my mind, and the logic
has to be written for each aspect anyway, I find it simpler just to divide the
layers as I'm writing the code in the first place. The total code size is
roughly the same, but the structure is cleaner and much, much easier to modify
as the application evolves.
- Lew