Is there a consensus on how to check a polymorphic instance?

Donn Cave donn at u.washington.edu
Tue Nov 23 13:13:09 EST 2004


In article <Nq6dneGDxsmm9T7cRVn-rw at rogers.com>,
 "Dan Perl" <danperl at rogers.com> wrote:
> "Steven Bethard" <steven.bethard at gmail.com> wrote in message 
> news:lkCod.88653$5K2.13406 at attbi_s03...

> > The big question, I guess, is what do you want to happen if a user did not 
> > inherit from your base class, but still provides all the appropriate 
> > functionality?  In a dynamically-typed language like Python the answer is 
> > usually that the user's class should still be considered valid, though of 
> > course there are exceptions to this rule.
> 
> 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"?  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 
> 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".  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?

Not only are there many definitions of polymorphism, there are
several kinds of polymorphism, each with many definitions.  You
could spend some time with a web search engine and get lots of
reading material on this, and I think you would find that a good
deal of it is coming from a point of view that kind of tends to
ignore object oriented programming altogether.  Check it out.
If you want to stay with the more immediately relevant OOP
thinking on this, search for polymorphism and smalltalk.

Note that C++ and Java need two mechanisms in support of something
approximating parametric polymorphism.  The subtype polymorphism
I think you're thinking of is the classic OO device, but it doesn't
support really generic functions and types.  The template system
has been bolted onto these languages (I gather Java has one now)
for this purpose.  With these two mechanisms, they more or less
support parametric polymorphism, in a statically typed, compiled
language.  Python is not statically typed, of course, so where
the literature about parametric polymorphism focuses on types
you have to decide for yourself how important that is in principle.
In the end it of course doesn't really matter what you call it.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list