newbie-question: interfaces

Paul Rubin phr-n2002a at nightsong.com
Sat Apr 13 13:52:20 EDT 2002


Patrick W <xnexau at yahoo.com.au> writes:
> Do you have a technical reason to actually want interfaces, or are you
> simply experimenting with the concept?
> 
> As far as I can see, which is admittedly not that far, interfaces
> don't really serve a useful purpose in Python. If you want
> polymorphism in statically typed OO languages like C++ and Java, you
> need to design your functions and methods to accept only objects
> descended from a known type. But in Python, the type need not
> (actually cannot) be specified at design time, so what purpose would
> an interface serve? Wouldn't it be better to just inherit
> _implementation_ when necessary, rather than to inherit pure
> interfaces?
> 
> I ask this not to be a prick, but to find out if I'm missing something
> important.

The purposes of interfaces in java is mostly to provide a form of multiple
inheritance.  Java doesn't support multiple base classes, so interfaces
are a workaround for that.  Python supports multiple base classes directly
so it doesn't need a workaround.



More information about the Python-list mailing list