struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yansheng Lin" <yansheng....@isogis.com>
Subject RE: [OT] Use of Static Methods
Date Wed, 09 Jul 2003 16:49:32 GMT
I gave this a bit of thought before.  I felt in some situations, static methods
and instances are preferred.  For example, if you want to synchronize a query
method.  Or in some situations where overriding is rare, i.e.,
java.util.Calendar.  


-----Original Message-----
From: David Graham [mailto:grahamdavid1980@yahoo.com] 
Sent: July 9, 2003 10:22 AM
To: Struts Users Mailing List
Subject: RE: [OT] Use of Static Methods


> 
> One of my programmers asked me whether or not it is OK to define helper
> methods as 'static' - and I realized that I didn't know the answer.  So
> I
> guess the question is, in a web application, can common code be factored
> out
> to a helper class and marked as 'static'?  

Static methods are evil for many reasons including philosophical (they're
not OO) and practical (you can't override their behavior).  You should use
a Singleton class with non-static methods.

Struts' RequestUtils class is a good example of why you should never use
static methods.  Developers want to override their behavior but can't
because everything is static.

David

> Are there any major problems
> with
> doing this?  I should know the answer, but just can't put my thumb on it
> right now.... 8)
> 
> TIA!
> 
> Jerry Jalenak
> Team Lead, Web Publishing
> LabOne, Inc.
> 10101 Renner Blvd.
> Lenexa, KS  66219
> (913) 577-1496
> 
> jerry.jalenak@labone.com
> 
> 
> This transmission (and any information attached to it) may be
> confidential and
> is intended solely for the use of the individual or entity to which it
> is
> addressed. If you are not the intended recipient or the person
> responsible for
> delivering the transmission to the intended recipient, be advised that
> you have
> received this transmission in error and that any use, dissemination,
> forwarding,
> printing, or copying of this information is strictly prohibited. If you
> have
> received this transmission in error, please immediately notify LabOne at
> the
> following email address: securityincidentreporting@labone.com
> 
> 
> 
> ---------------------------------------------------------------------
> 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
> 


__________________________________
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


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


Mime
View raw message