On Sun, 01 Jun 2003 17:54:06 -0300, Jos� Ventura wrote: > I have a use case in wich a user will be created if its ID is null, or > updated otherwise. > > What would be the preferrable approach? > > a) My business services layer provides both createUser() and > updateUser(), and I determine wich one to call inside my Action (by > testing user.getId() ), or: > > b) My business services layer provides a saveUser() method wich will > have the necessary logic inside. This way all my Action needs to do is > build a User object and pass it to the service layer. > > I like the second one better. However, I've read that Struts actions can > be considered part of the controller layer; the first option above does > treat the action as a "controller" (there's logic in it), whereas option > b) considers it to be something more presentation-bound (almost no > logic, simply converts requests into objects). > > Are there any advantages/pitfalls to these strategies?
With the scenario you described above, I'd lean towards the second approach although I don't think one approach is that much superior than the other. I usually like to know whether it's going to be an update or an create before I even get to the Action because I often like to display special stuff on the form if it's a new create vs an update (such as checking some flag and displaying the appropriate header - "Create User" vs "Update User"). So since I already know what the user is attempting to do I like having a Dispatch action set up with my CRUD methods... create, update, etc. so by the time I'm in the Action I already know what business logic I need to call. If you end up wanting to redirect control when the business logic is finished (new insert vs update) then either way you are going to need some way to tell what type of operation was performed, so you can either find out before doing the business method or after. However, if the control never changes based on whether it's a createUser or updateUser than I'd opt for option B since your controller then doesn't care what type of operation it was. -- Rick --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

