newbie-question: interfaces

logistix logstx at bellatlantic.net
Sat Apr 13 14:51:58 EDT 2002


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

Interfaces are important if you want to enforce a design-by-contract.
Granted, in Python you can query a class at runtime to see if it implements
a property or method, but this doesn't guarantee that the method does what
you want it to do semantically.  (Just because a function is named foo, it
doesn't mean it foos the way you want it to.)

Not to be a prick either, but if you're not using interfaces or ABC's, then
you're not taking advantage of the true goals of OO programming, you're just
warping the function names and data structures for your convienence.  The
whole point of OO is to deal through abstract interfaces that hide the
implementation details.





More information about the Python-list mailing list