super() and multiple inheritance failure

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Sep 26 02:02:12 EDT 2009


En 2009年9月26日 01:48:08 -0300, Steven D'Aprano 
<steve at remove-this-cybersource.com.au> escribió:
> I'm aiming for some sort of polymorphic inheritance: in a method, if the
> argument meets some condition, inherit from PClass, if it meets another
> condition inherit from NClass, and so on. Is there are standard name for
> this idea?

That doesn't look like an inheritance relationship ("is a").
If you say "from now on, act as a PClass, until further notice" and later 
"now, act as a NClass" you're using the Strategy pattern.
If you decide at every invocation which method to call, it's a dispatcher; 
you may use a dictionary to map each alternative to the function to be 
invoked. If it only depends on the type of the argument, there is a hidden 
gem in pkgutil (simplegeneric) that can help you.
-- 
Gabriel Genellina


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /