Python Polymorphism

Carlos Moreira duduca007 at yahoo.com
Thu May 12 16:00:45 EDT 2005


--- Fredrik Lundh <fredrik at pythonware.com> wrote:

> so phrases like

     <sniped>

>     (etc)
> 
> doesn't tell you that polymorphism is a fundamental
> part of the language,
> and used all over the place.  or did you have a
> non-OO meaning of the
> word in mind?

Ok, I prefer to think that I could be more specific.
So, let's try again.
Supose that I want to create two methos (inside a
class) with exactly same name, but number of
parameters different:

class myClass:
     myAttribute = 0
     def myMethod(self):
          self.myAttribute += 1
     def myMethod(self, myValue):
          self.myAttribute += myValue

Both method hold same identifier, the only difference
in them signture are parameters.
How could I simulate the situation above, using the
language dynamic link (or polymorphism, as you
prefer)?

Look, I don't want to use things like:

....
      def myMethod(self, myValue=None):
           if(not myValue):
                self.myAttribute += 1
           else:
                self.myAttribute += myValue
....

I want to use the power of polymorphism to modelate
the problem.

           Thanks and best regards

Cadu Moreira


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Find what you need with new enhanced search. 
http://info.mail.yahoo.com/mail_250



More information about the Python-list mailing list