Adding an interface to existing classes

Chris Angelico rosuav at gmail.com
Sun Dec 25 08:37:22 EST 2011


On Mon, Dec 26, 2011 at 12:27 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> There's nothing in the above that assumes that other has the same type as
> self. It's just that the type of other is ignored, and the type of self
> always wins. I find that a nice, clear rule: x.intersection(y) always
> returns a point with the same type as x.

The intersection of DrawableLine and DrawableLine is DrawablePoint.
That's not the same type as either of the inputs. Same if you seek the
intersection of two planes, which is a line - or two spheres, which is
a circle (with possible failure if they don't intersect).

ChrisA



More information about the Python-list mailing list