super() and multiple inheritance failure
ben+python at benfinney.id.au
Sat Sep 26 07:21:08 CEST 2009
Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:
> On Fri, 25 Sep 2009 21:03:09 -0700, Michele Simionato wrote:
> > I usually recommend avoiding multiple inheritance altogether.
> In my case, PClass and NClass are actually private classes, and it
> seemed like a nice way to avoid having to fill MyClass with
> slightly-different versions of each method to deal with slight
> variations in the arguments. 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?
Your description makes me suspect a code smell. If you want to decide at
method-invocation time whether branch A or branch B should be taken, it
doesn't sound much like a good use of inheritance at all.
The correct semantic of inheritance, after all, is the “is-a”
relationship; if you don't know at the time of writing the ‘MyClass’
whether it is-a ‘PClass’ or is-a ‘NClass’, then it's probably neither.
Instead, I would be reassessing the design and seeing whether object
composition (“has-a” relationships) fits better than inheritance.
\ “He may look like an idiot and talk like an idiot but don't let |
`\ that fool you. He really is an idiot.” —Groucho Marx |
More information about the Python-list