You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Denis Wang <dw...@brandmuscle.com> on 2003/07/16 16:29:28 UTC

is Struts action class a Design Pattern of utility class?

Hello, all,
I am not sure whether it is a good practice to:
eliminate instance variables from Struts action class; and
make all methods static.
Basically it turns the action class into a utility class.
Any comments?  Thanks.
Denis


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: is Struts action class a Design Pattern of utility class?

Posted by Andrew Hill <an...@gridnode.com>.
You shouldnt be using (modifiable) instance methods in an Action class as
actions need to be threadsafe - remember that could be any number of threads
executing that code at the same time! (This is where request attributes come
in handy) so certainly you should be eliminating instance variables and
either declaring them as local and passing between your methods or shoving
them in a bean you pass between your methods or putting them in request
attributes...

As for making your methods static... you probably dont want to do that - you
will be choking off your ability to subclass your action amoung other
things. Take a look in the archive at the discussion last week about
singletons vs statics.

Actions are a helper class not a utility class. They are invoked by the
RequestProcessor to assist it in processing the use case specific logic of
the action.

-----Original Message-----
From: Denis Wang [mailto:dwang@brandmuscle.com]
Sent: Wednesday, 16 July 2003 22:29
To: Struts Users Mailing List
Subject: is Struts action class a Design Pattern of utility class?


Hello, all,
I am not sure whether it is a good practice to:
eliminate instance variables from Struts action class; and
make all methods static.
Basically it turns the action class into a utility class.
Any comments?  Thanks.
Denis


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: is Struts action class a Design Pattern of utility class?

Posted by Sandeep Takhar <sa...@yahoo.com>.
You can still have static methods on the action, just
no instance variables that you update.  No instance
variables on actions is generally the case.

sandeep
--- David Graham <gr...@yahoo.com> wrote:
> --- Denis Wang <dw...@brandmuscle.com> wrote:
> > Hello, all,
> > I am not sure whether it is a good practice to:
> > eliminate instance variables from Struts action
> class; and
> > make all methods static.
> > Basically it turns the action class into a utility
> class.
> > Any comments?  Thanks.
> 
> Do *not* make your methods static.  Actions are
> Singletons and many
> threads may be running through them at one time so
> they must be thread
> safe.  This typically means you can't use instance
> variables to maintain
> state.  If you're interested in creating a new
> instance of each Action per
> request (thereby allowing you to use instance
> variables) you should look
> at overriding the
> RequestProcessor.processActionCreate() method.
> 
> David
> 
> 
> 
> > Denis
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> > 
> 
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: is Struts action class a Design Pattern of utility class?

Posted by David Graham <gr...@yahoo.com>.
--- Denis Wang <dw...@brandmuscle.com> wrote:
> Hello, all,
> I am not sure whether it is a good practice to:
> eliminate instance variables from Struts action class; and
> make all methods static.
> Basically it turns the action class into a utility class.
> Any comments?  Thanks.

Do *not* make your methods static.  Actions are Singletons and many
threads may be running through them at one time so they must be thread
safe.  This typically means you can't use instance variables to maintain
state.  If you're interested in creating a new instance of each Action per
request (thereby allowing you to use instance variables) you should look
at overriding the RequestProcessor.processActionCreate() method.

David



> Denis
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org