polymorphism in python

Jay O'Connor joconnor at cybermesa.com
Wed Nov 26 12:51:39 EST 2003


martin z wrote:

>A very interesting invention... does it work with parameter defaults?  Oh,
>and IIRC, the word you're looking for is "Function overloading" not
>"polymorphism".  Polymorphism refers to the ability to have completely
>different objects that can be used the same way, which Python always has.
>
>
>  
>

"Function overloading" is still one form of polymorphism.  Polymorphism 
as a concept can be approached in different ways, including function 
overloading, generic programming and inheritance.   Languages like 
Python are Smalltalk are very good at implementing polymorphism  based 
on sending a message to an object and as long as the object understands 
the message, it doesn't matter what the object is (part of their dynamic 
binding); but they are not as good at overloading based on argument 
types (how do you have two methods that have the same name but one takes 
a single integer argument and one takes a single string argument? 
answer, you have one function with an 'if' decision, or you have two 
functions with two different names, breaking the polymorphism, or for 
more complex objects you get doule-dispatch involved) . Languages like 
C++ and Java restrict polymorphism of objects to those within the 
hierarchy, but do allow for polymophism by function overloading; C++ and 
Ada also have polymopshim through generic programming (generics in Ada, 
templates in C++)





More information about the Python-list mailing list