Adding an interface to existing classes

Chris Angelico rosuav at gmail.com
Sun Dec 25 07:32:41 EST 2011


On Sun, Dec 25, 2011 at 11:10 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> class Point:  # An abstract class.
>    def intersect(self, other):
>        blah; blah; blah
>        return Point(x, y)  # No, wrong, bad!!! Don't do this.
>
> Instead:
>
>        return self.__class__(x, y)  # Better.

This would work if you were dealing with the intersection of two
points, but how do you use that sort of trick for different classes?

ChrisA



More information about the Python-list mailing list