[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Static Method performance
> What other reasons are there for not using a static methods ?
None really. Typically you'd make utility class method's
static so as to save the hastle and waste creating an instance
of that object.
My rules are:
- if the object does not have state or identity (no attributes),
then make the methods static and final. Final helps performance
if you don't plan on sub-classing. In my view, utility classes
are rarely subclassed so declaring methods final is something I
do quite alot even for classes that have identity and get
instantiated.
RE: final methods and classes, my designs follow Peter Coad's
method suggestion of avoiding specialization when ever the
subclass can change or is not certain to always be "a chevy"
or "a ford". My designs use alot (mostly) has-a associations,
with plugable behaviors, Command pattern etc, so my methods and
classes are largely declared final for performance.
Final methods can be in-lined at run time, since the VM knows
they can't be over-riden.
Appologies for jumping the track from static methods. :)
curt