What is the meaning of static and class methods ?
benn at cenix-bioscience.com
Tue Jun 29 09:56:36 CEST 2004
Neil Benn wrote:
> Michele Simionato wrote:
>> "fowlertrainer at anonym.hu" <fowlertrainer at anonym.hu> wrote in message
>> news:<mailman.213.1088407296.27577.python-list at python.org>...
>>> I want to anyone please send an example of class/static methods that
>>> HAVE MEANING.
>>> A real example, to I understand, why we need that methods in python.
>>> Thanx for it:
>> I may sound heretic, but I never thought their introduction as builtins
>> was a particularly clever idea. Python lived pretty well without them
>> for years and could continue living without them.
> While I agree that they are syntatic sugar, I believe that
> they make the design clearer and simpler. Suppose I design an
> abstract class of which there are several subclasses which provide
> concrete implementation. I can have a method is the abstract class
> such as getImplementation(self, pstrImplementationName), this method
> can then return the concrete implementation as asked for - a basic
> design <snip>
P.S. Sorry for my bad English - I'm English!
Here's another go!
While I agree that they are syntatic sugar, I believe that they
make the design clearer and simpler. Suppose I design an abstract class
of which there are several subclasses which provide concrete
implementation. I can have a method is the abstract class such as
getImplementation(self, pstrImplementationName), this method can then
return the concrete implementation as asked for - a basic design pattern.
Although it is true that I could put this method in module that holds
the class, the question you should really ask yourself is - does it
_belong_ in the module. In my opinion, it does not - it is a method
which belongs to the abstract class not the enclosing module which
shouldn't know about the fine implementation details of that class. The
next question is, why not make an abstract instance and use that - this
I think is wrong for two reasons - one it is a waste of an object
creation (although I admit this doesn't really matter, it is just ugly -
I am not a fan of doing something like dir("") to get the interface of
str, you should use dir(str)). The other reason is that it is an
abstract class - not designed to be instantiated just as a base template
for the other classes and (optionally) a factory.
However, I do get the point that this is just syntatical sugar but it
does make much more sense to me when both I'm doing my UML diagrams and
in my head.
One word of caution though, this is the first language I've used which
is not purely based on classes (such as Java, Eiffel and C#) - so I'm
coming from an OO point of view and not a Python-specific point of view.
Senior Automation Engineer
Tel : +49 (0)351 4173 154
e-mail : benn at cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com
More information about the Python-list