Are there 'Interfaces' in Python??
Markus Schaber
markus at schabi.de
Wed Sep 26 03:59:03 EDT 2001
Hi,
Richard Jones <richard at bizarsoftware.com.au> schrub:
> On Wednesday 26 September 2001 11:50, Paul Rubin wrote:
>> "tszeto" <tszeto at mindspring.com> writes:
>> > Was wondering if Python supported 'Interfaces' (something akin to
>> > Java interfaces)? Or if there's a workaround to get the same thing.
>>
>> Java interfaces are a workaround for java's non-support of multiple
>> base classes in objects. Python supports multiple base classes, so
>> it doesn't need a workaround for their absence.
>
> Er, no. They may be percieved as that, but since interfaces can't
> actually _do_ anything, whereas multiple inheritance _can_, I believe
> this is a dead herring.
It gets even somehow perverse in java: interfaces can bring code with
them in the never java versions, using inner classes:
public interface container {
public class embedded {
public void test() {
System.out.println("Hello");
}
}
}
> Interfaces are an extremely useful form of "type" checking for OO
> systems. Python already has "interfaces" in the form of agreed methods
> - witness the "pass a file-like object" requirements in a lot of APIs.
> An interface would just formalise that.
That is correct. In a lot of cases, such interfaces are a helpful
instrument to find bugs, because they force such agreements. But the
way they are implemented in Java, those are not as flexible as someone
could wish it in some cases. Python doesn't enforce anything, thus the
programmer has to know what he does - but he also can do whatever he
wants because he knows what he does.
markus
--
"The strength of the Constitution lies entirely in the determination of
each citizen to defend it. Only if every single citizen feels duty
bound to do his share in this defense are the constitutional rights
secure." -- Albert Einstein
More information about the Python-list
mailing list