Just to make sure this is clear, your listener should be talking to a
service, not directly to your DAO.
Beyond that, some of this is really a personal preference issue, but when I
find myself with a method called doABunchOfStuff() that has a bunch of
conditionals in it, that smells bad to me. More methods that do discrete
things is always preferable to a single method that does a bunch of
different things. Makes it far easier to debug, maintain, and extend.
> This would seem
> like a good way to reduce code redundancy and increase its
> maintainability, but are we missing something?
The redundancy point is debatable I suppose, but when you think about your
backend as a service layer to the rest of your app, the fact that you have
a method in your listener that merely calls a method in your service seems
less redundant. We also do have the call-method command that you can use to
bypass listeners altogether if all the listener method is doing is pulling
data from a service.
I disagree with the maintainability point. I do tend to have a single
save() method that does a create or update based on whether or not an ID is
set on the object in question, but I can't imagine including the read and
delete actions as well. What would you even call a function that does all
four of those things? And to distinguish between a read, update, and delete
you'd have to pass an action in anyway ... at that point you have a real
mess IMO.
In my opinion you should always opt for code that is explicit, easy to
read, easy to debug, and easy to maintain. Discrete, single-purpose methods
help achieve this.
--
Matthew Woodward
ma...@mattwoodward.com
http://mpwoodward.posterous.com
identi.ca/Twitter: @mpwoodward
Please do not send me proprietary file formats such as Word, PowerPoint,
etc. as attachments.
http://www.gnu.org/philosophy/no-word-attachments.html
Some of the tutorials are likely outdated but if they aren't showing the
use of a service layer they should be. I've also personally moved to a
single DAO object instead of splitting between DAO for CRUD and gateway
for aggregate data.
> I didn't mean the read would be included, that's a totally separate
> function. Delete though is just a matter of checking the action
> between update/delete of a form (basically is normally done in a non-
> MachII app with a create/update/delete component with a switch
> statement). Generally would just call it updateObjectTable or the like
Again, personal preference, but that really doesn't make sense to me. To
me having save(myBean) and delete(myBean) is much more straight-forward
than updateMyTable(myBean, "delete") and the requisite conditionals in
your listener method. I just don't see what you're gaining by doing
things that way.
Yep, would be nice if someone would revisit those. ;-) We're always looking
for volunteers so if someone has the time, that's a great way to get
involved with the project.
Absolutely!
Here's a link to a presentation I gave to the Maryland CFUG a while
back--talks about architecting applications for multiple UI technologies
but I think it's a great illustration of the service layer concept.
http://adobechats.adobe.acrobat.com/p52512658/