On Apr 15, 2004, at 1:13 PM, Paul Barry wrote:
I doesn't seem like this logic belongs in the DAO either, because if you don't want that kind of logic mixed in with code to get the data out of the database. Does it belong in the business objects, maybe by expanding the Widget object like this?
public Widget { public int getId(); public User getCreator(); public boolean canDelete(UserBO); }
No way.
And then canDelete would in turn call a DAO to check that? Or would a separate layer be better, like this:
public WidgetLogic { public boolean canDeleteWidget(User, Widget); }
That's better, but... if you're going to create a class that's dedicated to supporting a specific function, why not just have the class that performs the function encapsulate the details? The following might be considered an implementation of the Command design pattern, and does pretty much the same thing but with less steps:
public class DeleteWidgetCommand { DeleteWidgetCommand() { } // no-arg constructor void deleteWidget(User u, Widget w); }
You could also pass the User into the constructor, but one of the nice things about having a relatively stateless class like the above is it gives you flexibility for pooling/caching etc if that's something you end up needing. The actual connection between DeleteWidgetCommand and your persistence layer can be set up in a static initializer or static initializer block, assuming you can share a DeleteWidgetCommand object between clients.
This is not very different from using a session bean, but it avoids all that needless complexity if you're not already using EJB. (See <http://www.corej2eepatterns.com/Patterns2ndEd/ServiceFacade.htm>.) If your needs become more complex, you can refactor into a true service layer, which can keep the peanut butter out of your chocolate and the chocolate out of your peanut butter.
Just some ideas. Good luck.
-- Erik Price
<http://erikprice.com/>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]