The rule of thumb is to use composition instead of inheritance
generally.  (Joshua Bloch, Effective Java, pp. 71 ff.)  Otherwise you
end up with fragile software.  More specifically, if the superclass
and the subclasses are in the same package and under your control,
that is more likely to be where inheritance might be useful.  In this
instance, putting these far less than generic requirements into
inheritance rather than composition is not good coding.  The problem
is that, unlike method invocation in composition, inhertitance breaks
incapsulation in classes.  This is a serious problem that should be
seen as a problem.

Consequently, I would highly recommend that you follow sound
architectural principles and build a simple class or application to
test the user which is then used in something like a two liner, e.g.
ActionForward forward = new UserCheck().checkUser(request);

ifIforward != null) {
  retun forward;
}



On 5/17/05, Joe Germuska <[EMAIL PROTECTED]> wrote:
>  From my first take on your description of the problem, I don't think
> that subclassing ActionForward is the area of Struts where you would
> enforce this.
> 
> For a new app, the simplest solution is an abstract subclass of
> Action which all of your classes extend; your subclass implements
> execute, where you put your per-request logic, and then calls another
> (abstract) method like 'doExecute", which is implemented in your
> concrete classes.  The biggest problem with this solution is that you
> "blow" your one chance at Java inheritance, so if you want to use a
> variety of superclasses, you have a lot of overhead.  But it's
> conceptually pretty simple and good for many cases.
> 
> In your case, since you've already written a lot of code, you may
> want to go straight to the more sophisticated solution, which would
> involve subclassing RequestProcessor (or TilesRequestProcessor) and
> override "processPreprocess" or "processRoles".  Assuming that you
> can implement the logic you need with whatever values are passed in
> to those methods, this provides a pretty straightforward way to do
> things.
> 
> Of course, in Struts 1.3, the ComposableRequestProcessor makes this
> even easier.
> 
> Joe
> 
> 
> At 1:48 PM -0500 5/17/05, Lee Harrington wrote:
> >I want to check to see if the user is logged in before performing any
> >action, and redirect to the login page if they are not.
> >
> >For example...they have a page open and their session times out....and
> >then they click a button.  Right now an error occurs because they are
> >no longer logged in.
> >
> >I wrote a bit of code that if I put it in the beggining of an action
> >class...does just that.  But I don't want to have to put this in the
> >front of each of my actions (particularly since I've already written a
> >good portion of the app).
> >
> >Do I solve this by subclassing the action forward -- or in some other way?
> >
> >Lee
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> 
> --
> 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]
> 
> 


-- 
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

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

Reply via email to