What is the meaning of static and class methods ?
benn at cenix-bioscience.com
Tue Jun 29 09:47:10 CEST 2004
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 pattern.
Although it is true that I could put this in module that holds the
class, the question you should really ask yourself is - does it _belong_
there. In my opinion, it does not - it is a method which belongs to the
abstract class not the enclosing module which doesn't know . 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.
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 just
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
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