Does Python support interfaces?

Justin Sheehy dworkin at ccs.neu.edu
Mon Jul 17 21:17:30 EDT 2000


Randall Parker <rgparker at west.net> writes:

> 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?

Better yet, Python doesn't make you do all of that work.

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.

In any case, it sounds like you should read a little more about
Python.  There generally isn't any explicit type-declaration, and by
extension, casting.  "Casting" a Python object is not a very
meaningful statement.

-Justin

 




More information about the Python-list mailing list