Am I missing something with Python not having interfaces?
Daniel Marcel Eichler
onsen-neko at gmx.net
Wed May 7 15:19:30 EDT 2008
Am Dienstag 06 Mai 2008 16:07:01 schrieb Mike Driscoll:
> If so, then it looks like an Interface is a generic class with method
> stubs. You can do that with Python just as easily by creating empty
> methods with just the "pass" keyword.
Well, no. It's a litte different. Interfaces force to implement methods.
Simple inheritance with method-stubs can't garantee that a specific
method is reimplementat in a sub-class. Interfaces work at
compile-time, while method-stubs raise at their first call, so in worst
case, never (when the developer is available).
> Since it's just a construct to implement polymorphism, I don't think
> you'll lose anything. However, Python does not require you to re-
> implement every method of the class it is inheriting from.
That's the point. Interfaces garantee that a duck is a duck, an not only
a chicken that quack.
> You can just override those that you want and leave the others alone.
Not always desirable. But often enough ;)
More information about the Python-list
mailing list