[Python-3000] Implementations: A syntax for extending method dispatching beyond type/class inheritance

Jan Grant jan.grant at bristol.ac.uk
Wed Dec 6 10:20:43 CET 2006

On Mon, 4 Dec 2006, Bill Janssen wrote:

> Jim Jewett writes:
> > On 12/3/06, Bill Janssen <janssen at parc.com> wrote:
> > > > Implementations are used to make Method Dispatching more flexible by
> > > > allowing a class to claim that it acts like another class/type even
> > > > though it is not derived from that class/type.
> > 
> > > I'm not sure just what this adds over the simple "change_class"
> > > function that I've posted twice already.  Is there an implementation
> > > efficiency argument here?
> > 
> > (1)  Interfaces can be placed on a separate (presumably light-weight)
> > inheritance hierarchy.
> I know it looks this way, but I think you'd just be changing one
> inheritance mechanism for another.  No one would use the one that's
> already there; they'd just use this one instead.  And I don't really
> see how it's lighter-weight -- can you explain that?

With interfaces, it's not really about inheritance (although it might 
look like it). Inheritance is an implementation aspect of classes. 
Between interfaces, the question is simply one of _polymorphism_. Can 
members of one type be used as members of another type?

Interfaces describe types: they are contracts. They detail the 
responsiblities of the user of the interface, and the promises that the 
provider of the interface makes if those responsibilities are met.

Classes (and inheritance) are just one way of implementing those types. 
That is, the class mechanism provides encapsulation; interfaces are the 
vehicle for abstraction and polymorphism.

This might sound like semantic nit-picking, but the description of types 
and API contracts is the prime thing I'm looking for in an interface 
mechanism. Although the role that I see interfaces playing can be met by 
ABCs, there's always a sneaking tendency to slip some implementation 
detail into the ABC: that is, I see ABCs as an implementation approach 
to interfaces for a language that doesn't have the latter as a 
first-class language feature.

Given a type system (via interfaces or ABCs), Phillip's GFs are 
an interesting extension of Python's capabilities. The use of 
interfaces to express APIs plus the (perhaps only human-readable) 
semantic constraints on those is a useful feature in its own right.


jan grant, ISYS, University of Bristol. http://www.bris.ac.uk/
Tel +44 (0)117 3317661   http://ioctl.org/jan/
Semantic rules, OK?

More information about the Python-3000 mailing list