On 4/17/05, Rick Reumann <[EMAIL PROTECTED]> wrote:
> Michael J. wrote the following on 4/16/2005 2:24 PM:
> > Action class defines getResources(HttpServletRequest) as follows:
> >
> > protected MessageResources getResources(HttpServletRequest request) {
> >   return ((MessageResources) request.getAttribute(Globals.MESSAGES_KEY));
> >  }
> >
> > I don't see why this method is not static. Hopefully, this will be
> > refactored.
> 
> Hopefully it WON'T be. Why would you want it static? If you wanted to
> provide your own implementation of ActionForm, I wouldn't want this base
> class method being static since an instance method in my subclass can't
> override it (it can only hide it). Statics are usually a bad idea if you
> plan to use any sort of inheritance.
> 
> http://java.sun.com/docs/books/tutorial/java/javaOO/override.html
> 
> --
> Rick

I see your point. So what choices are available? 

* Make a separate static method in a utility class.
  Actually, this is already done: getResources() 
  in org.apache.struts.validator.Resources
  does exactly what original question author asked for.

* Make method public. I don't see how this can harm in this 
  particular situation.

* Make method static. You are against it, but let's see.

getResources() is a utility method. Most likely, one would not
redefine it for every child type. At most, one would redefine this
method only once in the root of the hierarchy, and then just call it
throughout the hierarchy. In this case the fact that this method is
static, won't make a difference, as long as all classes are cast to
the root class of custom hierarchy. But I see how it can cause bugs if
proper typecast is not made. On the other hand, Struts uses typecasts
all around, starting from casting Form class to a particular form
bean.

Michael.

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

Reply via email to