Missing interfaces in Python...

Neal Becker ndbecker2 at gmail.com
Wed Apr 19 10:06:10 EDT 2006


redefined.horizons at gmail.com wrote:

> I'm coming from a Java background, so please don't stone me...
> 
> I see that Python is missing "interfaces". The concept of an interface
> is a key to good programming design in Java, but I've read that they
> aren't really necessary in Python. I am wondering what technique I can
> use in Python to get the same benefits to a program design that I would
> get with interfaces in Java.
> 
> For example, if I want to have a program with a Car object, and a Bus
> object. I want both of these objects to present a common group of
> methods that can be used by Mechanic objects, but slightly different
> methods that can be used by Driver objects.
> 
> In Java I would accomplish this by defining an IFixable interface that
> would be implemented by both the Car and Bus objects. Mechanic objects
> would work with any object implementing this interface.
> 
> How would I approach this problem in Python? I think I would use an
> abstract class instead of an interface for IFixable, since Python
> supports multiple inheritance, but I'm not sure this is correct.
> 
> Thanks for any suggestions.
> 

I see various answers that Python doesn't need interfaces.  OTOH, there are
responses that some large Python apps have implemented them (e.g., zope). 
Does anyone have an explanation of why these large systems felt they needed
to implement interfaces?




More information about the Python-list mailing list