Needed: Real-world examples for Python's Cooperative Multiple Inheritance
Paul Rubin
no.email at nospam.invalid
Thu Nov 25 18:34:33 EST 2010
Raymond Hettinger <python at rcn.com> writes:
> I'm writing-up more guidance on how to use super() and would like to
> point at some real-world Python examples of cooperative multiple
> inheritance.
I'd mention the SocketServer library, except I'm not sure what you
mean by "cooperative", so I don't know if that counts.
The few times I've tried to use multiple inheritance, I think it wasn't
the right idea for what I was doing. It turns into a big mess quite
easily.
The classic example though is a window system, where you have a "window"
class, and a "scroll bar" class, and a "drop-down menu" class, etc. and
if you want a window with a scroll bar and a drop-down menu, you inherit
from all three of those classes. They each have to support (e.g.) a
"redraw" operation, so automatic method combination figures out what to
call.
I''ve mostly seen this stuff in connection with Lisp. If you look at a
CLOS manual you can probably find examples. There are also some
examples in the old CADR manual, using the MIT Flavors system which
predated CLOS. That manual is online now:
http://common-lisp.net/project/bknr/static/lmman/frontpage.html
The object system is documented in this chapter:
http://common-lisp.net/project/bknr/static/lmman/flavor.xml
The paragraph about "defwrapper" gives a clear view into the machinery.
More information about the Python-list
mailing list