[ANN] Multimethod.py -- multimethods for Python
Gordon McMillan
gmcm at hypernet.com
Tue Jan 11 12:59:28 EST 2000
Doug Hellmann wrote:
> How is this different from function overloading, as implemented
> in C++? I'm not a C++ user, but my impression is the effect
> would be the same. Is that the point?
Not at all. C++ (and Java) are limited to figuring out one
override / overload at a time. If you are dealing with base class
pointers, you need to bounce the message around for awhile
to resolve all of them. First, C++ will discover the proper
derived class (the override), and then the proper overload.
Unfortunately, this means declaring scads of methods which
don't do anything except let the language stumble through the
resolution.
So in order to do a nice simple case:
widget->process(event)
You need to do something like:
Widget::process(Event e) // not actually used
Button::process(Event e) {e->getProcessedBy(this);}
Text::process(Event e) {e->getProcessedBy(this);}
SpewEvent::getProcessedBy(Button) ...
BarfEvent::getProcessedBy(Text)...
but you also need to fill in most of the other squares of the
cartesian product, or the language gets mad at you.
say-what-I-want-you-to-say-not-what-you-mean-ly y'rs
- Gordon
More information about the Python-list
mailing list