Is this Pythonic?
bdesth.quelquechose at free.quelquepart.fr
Mon Aug 1 22:50:34 CEST 2005
Caleb Hattingh a écrit :
> To my mind, this kind of setup (interface class, or abstact class
are two different things.
> more usually used in static languages
>to benefit polymorphism
This is a good reason to use an interface in Java. C++ has no notion of
'interface', so you have to use abstract classes to achieve the same result.
> - but
> python is dynamically typed, so in which situations would this setup be
> useful in a python program?
Abstract classes ? When you want to factor out common implementation in
a base class and force derived class to implement specific parts. One
common use case is the template method (aka "hollywood", aka "don't call
us, we'll call you") pattern.
> You see, I expected your post to say that
> it wouldn't even be necessary, but you didn't :)
Implementation inheritance is never "necessary". Nor are OO, modularity,
structured programming, and human-readable programming languages !-)
It's a fact that inheritence being "only" (err... should I say "mostly"
?) an implementation mechanism in dynamic languages, class hierarchies
tends to be much more flat. But this doesn't mean that abstract base
classes are useless.
> I have spent a little effort training myself not to bother setting up
> class hierarchies like this in python
I had this pattern too.
More information about the Python-list