Interfaces != Multiple Inheritance [was Re: python development practices?]

Andrew Dalke dalke at dalkescientific.com
Tue Oct 30 21:25:27 EST 2001


Richard Jones:
>Java interfaces != multiple inheritance.
>
>They address completely different issues. Mutliple inheritance allows one
to
>include functionality from multiple base classes in one step. An interface
>indicates that your class implements a specific set of methods. Interfaces
>don't implement functionality, therefore indicating that your class
>implements multiple interfaces doesn't add any additional functionality.

Who says the base class needs to implement functionality?

class SpamInterface:
  def sing(self):
    raise NotImplementedError

class EggsInterface:
  def fry(self):
    raise NotImplementedError

class Food(SpamInterface, EggsInterface):
  def sing(self):
    return "Spam, spam, spam, spam!"
  def fry(self):
    return "Sizzle."

issubclass(Food, SpamInterface)

For that matter, who says that espousing an interface means that
interface is properly implemented?  Since you have to have the
regression tests anyway, what's the point of declaring an interface
when the act of testing it is sufficient to show that the needed
API is available?

                    Andrew
                    dalke at dalkescientific.com







More information about the Python-list mailing list