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

Dan Perl danperl at rogers.com
Tue Nov 23 11:41:28 EST 2004


"Steven Bethard" <steven.bethard at gmail.com> wrote in message 
news:lkCod.88653$5K2.13406 at attbi_s03...
> Mike Meng wrote:
>> Here is my problem. My project needs to parse some user input
>> string according to  specific rules. The rules can be defined with a
>> string, a CSV file, an XML file, and other forms. Followed the standard
>> OO style,  I designed a dictionary-like base class to abstract those
>> different sources and provides other parts a uniform interface to query
>> those rules.  I put some hard code into the base class and expect user
>> to inherit from it.
>
> 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?

Dan 





More information about the Python-list mailing list