[Python-3000] Implementations: A syntax for extending method dispatching beyond type/class inheritance
janssen at parc.com
Wed Dec 6 20:09:47 CET 2006
> Compared to ABCs, interfaces can also describe contracts that can be
> fulfilled with any object--not just class instances, but classes
> themselves, and functions.
Sure, and I appreciate that. But classes and functions are both
instances of types, and thus can have extra types mixed into them:
either marker types (no methods), or ABCs, or mix-ins that actually
provide extra functionality.
I'm arguing that most (all?) of the functionality of a new "stand-off"
interface system can already be achieved for the vast majority of
cases using a system that's already designed and implemented in
Python, the multiple-inheritance type system. After all, the "object"
still has to fulfill the "contract", and most of the time that means
it has to implement an interface of some kind. And it's going to be
difficult to do that if it doesn't have some kind of "connection" to
an implementation of that interface. Using types to provide that
connection is a simple and already-implemented mechanism.
There are some drawbacks to this approach, such as the fact that
changing the type of an instance later is (currently) fairly
expensive. But that's a reasonable target for optimization. Another
problem is that the basic Python types are somewhat poorly understood,
which is the point of the exercise at
More information about the Python-3000