struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Micael <caraun...@harbornet.com>
Subject RE: [OT] Use of Static Methods
Date Wed, 09 Jul 2003 21:58:17 GMT
Of course they do.  That is not the point.  "Care" does not mean 
exclusion.    You have stated some limited uses, which is what I said.  So, 
you are not disagreeing with what I said.  The problem is that many 
programmers do not really understand the nature of polymorphic behavior and 
its critical nature in OO programming.  I also, by the way, use other 
languages, but that does not make them, or static methods, OO programming.

At 04:31 PM 7/9/03 -0500, you wrote:
>I have to disagree that static methods do not somehow fit into an OO
>environment. They are integral parts of the FactoryMethod, Singleton,and
>ServiceLocator.Also as convenience methods for conversions from one type
>to another they are particularly handy. Not using static methods where
>appropriate because of a mistaken belief that they are somehow not "OO"
>will limit your programming.
>
>On Wed, 2003-07-09 at 15:48, Micael wrote:
> > I have to agree philosophically with the care that should be taken in 
> using
> > static methods.  They really have limited use in an OO environment.  They
> > are like doing procedural code.  You can run an entire Java program, by 
> the
> > way, without using the main(String [] params) method.  A lot of people
> > don't realize this.  You just use all static methods and data.  I have a
> > half hour program I run doing all sorts of things, including some snappy
> > graphics, math, etc., with no main method.  But, this is certainly not OO
> > programming.
> >
> > At 11:30 AM 7/9/03 -0700, you wrote:
> > >--- "Yee, Richard K,,DMDCWEST" <Yeerk@osd.pentagon.mil> wrote:
> > > > I and a lot of other developers would disagree with the statement
> > > > "Static methods are evil for many reasons including philosophical
> > > > (they're
> > > > not OO) and practical (you can't override their behavior)."
> > > >
> > > > 1) Whenever you write a method that only accesses static data of a
> > > > class,
> > > > you should declare the method as static.
> > >
> > >Yes you could declare it static; however, accessing static data isn't a
> > >sufficient condition for making a method static.
> > >
> > > >
> > > > 2) It is not correct to say that static methods can't be overriden. 
> They
> > > > can
> > > > be overridden with another static method. You can't override a static
> > > > method
> > > > to be non-static, however.
> > >
> > >That's incorrect.  Static methods cannot be overridden.
> > >
> > > >
> > > > 3) There are many cases where using the static modifier on a method is
> > > > totally appropriate. Typically, they are used on methods that provide
a
> > > > very
> > > > specific functionality that will never change.
> > >
> > >How can you possibly judge that functionality will never change in a
> > >particular method?  Except in very limited circumstances you can never
> > >assume that.  Just look at the assumption used in designing RequestUtils
> > >as static methods for an example.
> > >
> > > > Using the static modifier
> > > > on
> > > > such methods also reduces the overall memory footprint of an
> > > > application.
> > >
> > >That's a red herring argument.  The class is loaded regardless of static
> > >or non-static method calls.  A basic Java object is 8 bytes of memory.
> > >Are you going to give up on design principles for 8 lousy bytes?
> > >
> > >OO programs should be made up of objects passing messages to other
> > >objects, not calling global functions.
> > >
> > >David
> > >
> > > >
> > > > Regards,
> > > >
> > > > Richard
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > -----Original Message-----
> > > > From: David Graham [mailto:grahamdavid1980@yahoo.com]
> > > > Sent: Wednesday, July 09, 2003 9: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
> > > >
> > >
> > >
> > >__________________________________
> > >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
> >
> >
> >
> > LEGAL NOTICE
> >
> > This electronic mail  transmission and any accompanying documents contain
> > information belonging to the sender which may be confidential and legally
> > privileged.  This information is intended only for the use of the
> > individual or entity to whom this electronic mail transmission was sent as
> > indicated above. If you are not the intended recipient, any disclosure,
> > copying, distribution, or action taken in reliance on the contents of the
> > information contained in this transmission is strictly prohibited.  If you
> > have received this transmission in error, please delete the 
> message.  Thank
> > you
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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



LEGAL NOTICE

This electronic mail  transmission and any accompanying documents contain 
information belonging to the sender which may be confidential and legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of the 
information contained in this transmission is strictly prohibited.  If you 
have received this transmission in error, please delete the message.  Thank 
you  



---------------------------------------------------------------------
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