Obviously it's tough not to be too academic when you're not actually cutting code, but the general tack I like to take is to wrap those dependencies in classes of my own. So, in this case:

someDispatchMethod(...) {

(User)request.getSession().getAttribute("user");

you could instead have arranged to use a trivial subclass of ComposableRequestProcessor which overrides the "contextInstance" method to produce RicksOwnActionContext which implements the ActionContext interface, but which also has this method:


public User getUser() {
  return (User) this.getSessionScope().get("user");
}

Is this a huge gain? I don't know. But it's possible. And it means that you could test your class without needing to have a mock HttpServletRequest.

if ( user.isSomething() ) {
        //call this business method
        //if you get something odd back...
        //we need to add some flag into scope
        reuqest.setAttribute("something",whatever);
else {
  //do the usual
  //call business method
  //look at return and realize we need to set up the next
  //page we go to with something unique bc X condition was met
  //if something
     //so call some other business method to get me this List and pop
     request.setAttribute("neededList", list )
  //else maybe return from business was fine no need to set up request
  //leave
}

For these, I am moving towards defining simple beans which represent a use case scope and which, like the example above, provide typesafety and encapsulation. So, instead of sticking two different things into the request under different keys, you'd put only one (this UseCaseBean), and it would manage the references to any of the things your case is likely to need. (If it's a significant use case, then perhaps you'd keep it in session scope instead.) Then, rather than having to do a whole lot of coordination so that everyone knows the right names (and sometimes scopes) of attributes, you just ensure that the one bean is in the right place at the right time, and everything else operates purely on a "need-to-know" basis.


Joe

--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "Narrow minds are weapons made for mass destruction" -The Ex


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to