Pythonic Abstract Base Class / Interface
Michael Hudson
mwh at python.net
Tue Oct 28 08:08:41 EST 2003
Tom Evans <tom_evans_a at uk.co.yahoo.reverse> writes:
> My basic question:
> If I have a specific interface which I know is going to be implemented
> by a number of classes, but there is no implementation commonality
> between them, what is the preferred form for this in Python?
[...]
> So, as I see it I could:
> a) create a base class with stubs for all the interface and derive from that.
> b) create an empty base class and derive from that.
> c) just make the concrete classes directly with no inheritance commonality.
>
> Is there a clear pythonic way, or does it depend a bit more on the
> design of the specific program?
I'd say c) was probably the most pythonic, but it depends a bit. a)
might have some documentation value -- for instance, you could
document required relations between the methods in their docstrings.
Cheers,
mwh
--
In the 1950s and 60s there was a regular brain drain of young
Australians from the cities to London, but it was because of
money, culture and opportunity, not spiders.
-- Al Grant, ucam.chat, from Owen Dunn's review of the year
More information about the Python-list
mailing list