Hello all.
My question might not be viewed as a Struts question, but more along the
lines of an architecture question. But, on the other had, it is struts
architecture, so I'm ok! ;-)
This is the situation: some of our designers are creating subclasses of
Action, while others are creating subclasses of DispatchAction. Now,
there's some common functionality that needs to be executed by all
subclasses of both Action and DispatchAction. The way that we've done
it for Actions is by implementing execute in a base class and in it
calling an abstract method that subclasses need to implement, like this:
public class BaseAction extends Action {
protected abstract ActionMapping
internalExecute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response );
public ActionMapping
execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response ) {
// ... Perform common work here
return internalExecute( mapping, form, request, response );
}
And, of course, for our base subclass of DispatchAction, we do something
similar:
public class BaseDispatchAction extends DispatchAction {
public ActionMapping
execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response ) {
// ... Perform common pre-execution work here
return super.execute( mapping, form, request, response );
}
Plus, there are utility methods common to both BaseAction and
BaseDispatchAction.
Now, any half-decent coder's response to the phrase 'common
functionality' is to think, "is there a way that I can centralize this
work, to reduce the repeated code?"
So, my question is this: what is the best way to add common
functionality to subclasses of both Action and DispatchAction?
As DispatchAction is a subclass of Action, the initial thought is to add
it to Action, but that's un-necessarily messy.
Another way that I've thought of is to create a 'common action
functions' class, where I place implementations of all the functionality
I might use, and then in my BaseAction and BaseDispatchAction,
proxy/redirect to that CommonActionFunctions class. However, I try my
best to write the best code possible, and this isn't as clean as I'd
like it to be (I'm still duplicating method signatures, etc).
What other ways have people found to deal with this situation?
JDG
--
Jay Glanville
Web Developer
[EMAIL PROTECTED]
(613) 725-2030 x393
http://www.naturalconvergence.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]