Program to an interface, not an implementation
Mark McEahern
marklists at mceahern.com
Fri Jun 7 06:43:02 EDT 2002
[Egbert Bouwman]
> My next problem is on nearly the same page (17) of the GoF book:
> class versus interface (== type) inheritance, but in the python context.
As the following shows, inheritance in Python is implementation inheritance.
In this particular case, the subclass inherits a method they MUST override,
but you could easily provide an implementation that actually does something
too. I'm not sure whether this answers your question, though--I haven't
been following this thread.
class PersistentBase:
def save(self):
raise NotImplementedError
class Invoice(PersistentBase):
pass
i = Invoice()
try:
i.save()
except NotImplementedError:
pass
else:
raise
Cheers,
// mark
-
More information about the Python-list
mailing list