Are there 'Interfaces' in Python??
Tim Hammerquist
tim at vegeta.ath.cx
Tue Sep 25 22:12:49 EDT 2001
Me parece que Paul Rubin <phr-n2001 at nightsong.com> dijo:
> "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.
IOW, Python equivalents to Java interfaces are base-classes with virtual
functions, also called "mix-in" classes. eg:
class MyClass:
pass
class MyInterface:
def func1(self):
raise NotImplementedError # force virtual method
class MyInterfacingClass(MyClass,MyInterface):
def func1(self):
pass
HTH
--
Trust the computer industry to shorten the term "Year 2000" to Y2K. It
was this kind of thinking that got us in trouble in the first place.
-- Adrian Tyvand
More information about the Python-list
mailing list