[Tutor] class methods as static methods?

Alan Gauld alan.gauld at btinternet.com
Sun May 30 09:26:22 CEST 2010


"Alex Hall" <mehgcap at gmail.com> wrote

> that it will hit. I would like to not instantiate a Harpoon object,
> just call the Harpoon's getImpactCoords method and pass it the
> required arguments. Is this possible?

Others have pointed out that
a) This is possible using staticmetjhod or classmetjod decorators and
b) it seems a strange choice since you would expect the ability to
use more than one harpoon and hence be better with an instance...

I will add that if you really want a class method then maybe
you can do without the class completely and just use a function?

The usual reason for class methods is to operate on the
class as a whole - ie all instances - it is not to provide 
functionality
without any instances (except in languages without functions,
like Java, which really use static methods as a kluge to cover
their limitations!)

And functioons are much easiert to write and manage than
instanceless classes!

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list