On 10/6/06, Wesley Wannemacher <[EMAIL PROTECTED]> wrote:
Hello,
I'm exercising the 'Casual Friday' rule here to ask some general
questions. I apologize in advance if I break any list etiquette, but I
subscribed on Monday and have been waiting patiently for Friday so that
I can get these questions off my chest. Thanks!
Some folks don't wait until Fridays! :-)
I've been working on Java/JSP for a few years now and I recently decided
to try out struts (better late than never). In the past, I would
typically write a JDBC wrapper library to help me get to the database,
then write all of my code with little abstraction from SQL code. Being a
database guy as well, this made sense to me, and I could do quick easy
things like a 'QueryToTables' tag that would allow me to paste SQL code
right into a JSP and have the results of that query pasted nicely into
the output. For updates, I would build the form I needed (using my own
custom tags for input fields) and call into my JDBC wrapper to hit
stored procedures.
Err, yes. Quite so. I'm not a database kind of guy, so I'll trust that's good.
I picked up a copy of 'Struts Design and Programming: A Tutorial' and I
am learning the details of the libraries, but I've never written a
JavaBean (EJB or regular Bean). It seems that EJB isn't necessary, but
that regular JavaBeans are used heavily elsewhere. So, I figured I would
EJBs are not necessary for Struts apps. I led a team that produced a
pretty good sized Struts app that didn't even come close to using an
EJB.
start trying to figure out smart JavaBean Design (I don't really want to
have to refactor/redesign all of my core classes later when I'm more
experienced). The problem I have though is that all the books I have
laying around seem only to refer to plain ol' JavaBeans as GUI
components. If I understand correctly, to make an object a JB, I really
only have to have getters/setters for the properties I want to expose,
but can I have other methods that do other stuff? What suggestions would
you give someone who has never written a JavaBean before that is going
to begin working from the ground up on a new project? I figured I would
Now, JavaBeans are just very structured value objects. All their
attributes are exposed through getters and setters as you observed.
The trick with JavaBeans is to let them be single-purpose and don't
try to mix in a few extras here and there. Use them for transporting
data and create other business logic objects to handle the "doing
stuff". There'll be tears before bedtime if you forget this basic
rule.
use iBATIS for database persistence, so I've been reading about that as
well. I guess I'm just a bit paranoid about writing the 'middle layer'
between struts and the SQL code/server, so any advice on gotchas and/or
suggestions for struts-friendly 'middle layer' design would be much
appreciated.
The next thing to do is to work hard to keep the view/controller layer
distinct from the model. On my apps, I like to have a static class
called API (really!) that acts as the API into the entire business
back end. Each behaviour that an Action might want to call is behind a
method on the API. Calls into the API pass in a Request object and
receive back a Reply object. This helps keep ActionForms out of the
model.
The next thing I would do (actually did) would be to create subsystems
within the model to handle the different kind of activities that the
system is going to perform. Going to store data? Have a persistence
subsystem. Going to print stuff? Have a print subsystem. Going to
communicate with devices? Have a device subsystem. You get the
picture.
I could go on a while, but that'll get you started.
Simon
--
simonpeter.org | simonpeter.com | techbook.info
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]