Pythonic Abstract Base Class / Interface
Tom Evans
tom_evans_a at uk.co.yahoo.reverse
Wed Oct 29 04:36:38 EST 2003
Tom Evans wrote:
> 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.
Thanks for all the responses. It would appear that there is no
One True Way. What I've learnt:
I was originally just whipping something up, not sure what the final
solution was going to look like. In that case, it would appear (c)
was the way to go.
If I wanted to document exactly what the interface should be once I'm sure
it's the right solution, (a) with document strings and raising
NotImplementedError might be a good place to put that documentation.
(btw, thanks -- I didn't know about NotImplementedError before)
On the face of it, (b) appears to be the loser. But it would give me
isinstance if I wanted it, and might allow me to convert more easily
from (a) to (c) in the future.
thanks to all,
Tom
More information about the Python-list
mailing list