> -----Original Message-----
> From: Erik Hatcher [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, December 05, 2002 1:48 PM
> To: [EMAIL PROTECTED]
> Subject: subclassing frustrations
> 
> 
> *everything should be an interface* :))
> 
> ARG... I'm having some frustrations with the built-in Struts Actions 
> (yeah, I know, I'm the author of one of them, 
> LookupDispatchAction, so 
> I'm guilty!)
> 
> I make it a standard practice to subclass Action to form a BaseAction 
> (using the template pattern, making execute final and calling a new 
> executeAction method).  I then template this further with a 
> BaseAdminAction which all administrative actions subclass from.  This 
> works all fine and dandy when all I want to do is plain actions.
> 
> But what about when I want to use DispatchAction or 
> LookupDispatchAction?  I cannot easily do this.  In my last project I 
> resorted to just cutting and pasting the LookupDispatchAction 
> code into 
> a new BaseLookupDispatchAction (which subclassed from my BaseAction), 
> and went around the very thing I created.
> 
> Do others have thoughts on this?  Suggestions on how I can 
> handle this 
> such that I actually can use the real LookupDispatchAction within a 
> custom BaseAdminAction subclassed action?
> 
> I hope that Struts2 is more interface-centric such that I 
> don't have to 
> resort to messing with my inheritance hierarchy to play nicely with 
> Struts.  How that plays out with form beans and the rationale 
> for them 
> being an actual class is still unclear to me, but in that case I'm ok 
> with creating my own BaseForm that extends from ValidatorForm (making 
> validate final so no developers can mess it up!) - so I 
> haven't run into 
> any form bean inheritance issues, only actions.
> 
> Thanks,
>       Erik

It seems to me that just making Action an interface wouldn't even solve
your problem.  Your problem is that you want to use inheritance for the
template method pattern, but you also want to use inheritance to reuse
functionality from the LookupDispatchAction.  The best solution I can
think of is to have your class subclass BaseAdminAction and delegate to
LookupDispatchAction.

for example

public class MyAction extends BaseAdminAction {
  // this is whatever your non-final execute method is called
  public ActionForward myExecute(ActionMapping mapping, ... ) {
    return new LookupDispatchAction().execute(mapping, ... );
  }
}

Even better, create a single LookupDispatchAction in the constructor and
reuse it across requests.  I haven't tried anything like this, but I
can't think of any reasons off-hand why it shouldn't work.  Any
comments?

-- 
Tim Moore / Blackboard Inc. / Software Engineer
1899 L Street, NW / 5th Floor / Washington, DC 20036
Phone 202-463-4860 ext. 258 / Fax 202-463-4863


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

Reply via email to