Am I missing something with Python not having interfaces?
Luis Zarrabeitia
kyrie at uh.cu
Wed May 7 16:39:30 EDT 2008
On Wednesday 07 May 2008 03:19:30 pm Daniel Marcel Eichler wrote:
> Am Dienstag 06 Mai 2008 16:07:01 schrieb Mike Driscoll:
>
> 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).
<Pseudo-java code>
class MyClass implements MyInterfaceWithPassMethod {
function Pass() {
}
}
</pseudo-java code>
There you have it, interfaces are not enough to ensure that the implementors
actually implement the methods. They are useful for warning at compile time
if there is a missing method, but nothing more. I believe you could achieve a
very similar warning in python using some kind of Interface metaclass (too
lazy right now to hack a proof of concept, but it looks doable).
I actually like the Interface concept... as portrayed by zope.Interfaces and
pyprotocols (not the same thing, but I like them), and the ABCs (these, not
so much). But Java interfaces are barely a replacement for multiple
inheritance+abstract methods.
> That's the point. Interfaces garantee that a duck is a duck, an not only
> a chicken that quack.
Not really. (See the NotImplementedExceptions in .NET 1.1 and window forms,
and/or their TabbedControl/TabPage background color attribute. Can't find
them now, as I don't have .NET anymore, but I consider that an example of why
the static typing are... overrated)
--
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
More information about the Python-list
mailing list