replace a method in class: how?
onurb at xiludom.gro
Tue Jun 27 10:42:45 CEST 2006
Maric Michaud wrote:
> Le mardi 27 juin 2006 06:21, Bruno Desthuilliers a écrit :
>>Maric Michaud a écrit :
>>>In OOP Methods are defined in *classes* not in any arbitrary object
>>Chapter and verse, please ? AFAIK, the first O in OOP stands for
>>"object", not for "class" !-)
> Hard to find it, indeed.
>>Classes are just an implementation convenience, and the fact that the
>>class-based model is the most usual one doesn't imply it's the only
There other prototype-based languages. And truth is that while having
than to Java or C++.
> Well, there are no methods in this model, only functions.
Nope. There are closures, not simple functions.
And FWIW, what do you think methods are in Python ? Yes, functions,
wrapped in a special descriptor.
>>So there's no reason one shouldn't override (or add) a method
>>on a per-object basis. As a matter of fact, it's perfectly legal (and
>>can be very convenient) to do so in Python.
> I never saw the term "method" used for anything except for what it means for
Help on class instancemethod in module __builtin__:
| instancemethod(function, instance, class)
| Create an instance method object.
> and moreover, the class model, even if it's just an implementation,
> it's the one chosen by python.
There's a superficial similarity with "mainstream" static OOPLs like
Java/C++ etc. But Python's classes, and their relation to instances, are
as dynamic as can be, and really very different from what's in most books.
> For the common understanding of the model, IMHO, classes bind methods,
> instances bind functions.
In Python, a class is nothing more than an object that:
1/ act as an object factory
2/ serves as delegatee for instances.
FWIW, the proper constructor (__new__, not __init__) is free to return
instances of any other class (as long as the initializer signature is
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list