Is there a consensus on how to check a polymorphic instance?
aleaxit at yahoo.com
Mon Nov 29 01:46:13 CET 2004
Dan Perl <danperl at rogers.com> wrote:
> I have a question here, as we are discussing now protocol interfaces vs.
> inheritance. Is using a class that implements a protocol without inheriting
> from a base class still "polymorphism"?
``still'' is inappropriate here. It is _fully_ polymorphism, of course.
It's known as signature-based polymorphism. C++ has it in templates,
only, where it's the basis of the whole power of the standard library
containers, algorithms, iterators, etc. Python has it everywhere,
except where some coder breaks everything with 'isinstance' or the like.
> There are probably many definitions
> for polymorphism and probably all those definitions can be interpreted in
> such a way that they accept also protocols. But what I would like to hear
Otherwise they're very broken and useless definitions.
> is what is the general opinion of people who use python. I am biased
> because I come from a C++ and Java background and I am still used to a
> certain practical meaning for "polymorphism".
One that doesn't apply to C++ templates?!
> But it's beginning to dawn on
> me that it is only a bias and polymorphism does apply also to python
> protocol interfaces. Is that generally accepted?
More information about the Python-list