Missing interfaces in Python...

Alex Martelli aleaxit at yahoo.com
Wed Apr 19 00:06:17 EDT 2006


Roy Smith <roy at panix.com> wrote:

> Peter Maas  <peter.maas at somewhere.com> wrote:
> > He probably means that with interfaces one could test compliance
> > with the interface as a whole instead of testing each member and
> > each signature as a single piece.
> 
> All interfaces (as implemented by Java) prove is that your class has a
> bunch of methods with the right names and signatures.  It doesn't
> prove that those methods do the right things.  It's like having a

There's a _tiny_ bit more -- accidental clashes of methodnames are more
likely to be avoided.  I.e.,

interface ILottery {
    void draw();
};

interface IGunslinger {
    void draw();
};

interface IPainter {
    void draw();
};

A class asserting, e.g., "implements IPainter", doesn't thereby risk
being accidentally misused where an IGunslinger is required (OTOH,
implementing >1 of these IS a bother, but that's sort of inevitable).


Alex



More information about the Python-list mailing list