From: fredrik at pythonware.com (Fredrik Lundh)
Date: Thu, 15 Apr 1999 14:00:24 GMT
Subject: Different methods with same name but different signature?
References: <3716909C.D8D1B372@fedex.com>
Message-ID: <005201be8748$51e0bab0$f29b12c2@pythonware.com>
X-UID: 892                                                  

frederic pinel wrote:
> While trying to implement the visitor pattern in Python, I ran into the
> following problem:
> 
> My class needs to have 2 (or more) different methods, but with the same
> name, the difference being the signature (an object in my case),
> unfortunately Pyhton interprets this as an overidding, and only
> considers the last method defined.

well, python doesn't allow you to specify argument types,
so there's no way to tell the difference anyway...

> - using a single method, but checking isinstance() of the object passed
> to switch to the right code,
> - using different names for the methods,

the second method is preferred -- it's faster, easier to
understand, and less error-prone

imho, it's also an improvement over the pure visitor pattern,
since it allows you to generate "logical events" that doesn't
correspond to "physical" data instances in your model.

</F>





