Does Python support interfaces?
Aahz Maruch
aahz at netcom.com
Tue Jul 18 10:16:16 EDT 2000
In article <MPG.13dd4ec32cbe48e98982a at news.onlynews.com>,
Randall Parker <rgparker at west.net> wrote:
>
>I'm quite new to Python. For those who are familiar with Java interfaces:
>Does Python have a similar facility?
>
>Can one declare interfaces, then declare that a class implements some
>interface, instantiate an object of that class type, and then cast it to
>an interface that it is declared to support and then pass it around as a
>reference to that interface type and make calls to methods of that
>interface type?
Let me expand on Justin's post:
Interfaces are *everything* in Python; you use inheritance only when you
want to borrow behavior from an existing class. If I create a base
class called MyFileType and implemented all the standard methods and
attributes, Python would literally not notice that I was using a brand
new class as a file object. All the standard Python operations would
just work. No casting, no subclassing.
--
--- Aahz (Copyright 2000 by aahz at netcom.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
Q: In a lesbian relationship, who decides who gets to be the man?
A: It's two women. There is no man. That's the point.
More information about the Python-list
mailing list