is Struts action class a Design Pattern of utility class?

2003-07-16 Thread Denis Wang
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2003-07-16 Thread Andrew Hill
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:[EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


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



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

2003-07-16 Thread David Graham
--- Denis Wang [EMAIL PROTECTED] 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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


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

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



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

2003-07-16 Thread Sandeep Takhar
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 [EMAIL PROTECTED] wrote:
 --- Denis Wang [EMAIL PROTECTED] 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:
 [EMAIL PROTECTED]
  For additional commands, e-mail:
 [EMAIL PROTECTED]
  
 
 
 __
 Do you Yahoo!?
 SBC Yahoo! DSL - Now only $29.95 per month!
 http://sbc.yahoo.com
 

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


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

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