Does Python support interfaces?

Alex Martelli alex at magenta.com
Tue Jul 18 17:26:06 EDT 2000


"Eric Hopper" <hopper at omnifarious.mn.org> wrote in message
news:Rv_c5.1492$6E.294613 at ptah.visi.com...
> In article <vndlmz0b5jp.fsf at camelot-new.ccs.neu.edu>, Justin Sheehy
> <dworkin at ccs.neu.edu> wrote:
> >
> > Just define the class, and make sure that it provides the proper
> > interface.  Note that I'm not using "interface" with any special
> > language-dependent meaning here.  If it behaves properly, it behaves
> > properly, and that is all that matters.
>
> Whee!  Inheritance by mysteriously coinciding method names is so much fun!

Yep, it is exactly what C++ does in its templates.  Of course,
they're resolved at compile-time in C++, but then Python is
not about compile-time vs run-time distinctions, is it?

See Austern's excellent book on Generic Programming (and, also,
on the STL) about the GP metaconstruct he calls "concept", and
how and why it's not modeled by inheritance even in C++.  The
compiler cannot diagnose many kind of concept-violations
anyway (they're deeply semantic, e.g., the concept that a
certain function imposes a strict weak ordering) so little
is really gained by compile-time checks.


Alex






More information about the Python-list mailing list