Adding an interface to existing classes
Spencer Pearson
speeze.pearson at gmail.com
Thu Jan 5 02:56:29 EST 2012
(I'm sorry for my delayed response -- I've been travelling and not had
reliable Internet access.)
>> Spencer, i would re-think this entire project from the
>> beginning. You are trying to make an object out of everything. You
>> don't need to make an object of EVERYTHING.
>
> Very true.
I'm not sure I understand. Surely you're not both saying that I
shouldn't write a Point class? Here's an expression I'd like very
much to be able to type:
sphere1.intersect(sphere2).rotated(angle, axis)
If I represented points with something already defined, maybe a tuple
or a numpy array, then that would risk that the spheres were tangent,
that their intersection was not a Circle (a GeometricObject, with a
.rotated method), but a point (a tuple, without one).
On 2011-12-25, Steven D'Aprano <steve+comp.lang.python at pearwood.info>
wrote:
> class Line:
> intersection_kind = Point
> def intersection(self, other):
> blah()
> return self.intersection_kind(a, b)
>
> class DrawableLine(Line):
> intersection_kind = DrawablePoint
If I objected that the intersection of two Lines might, once in a blue
moon, be a Line (because they're the same line), this seems like it
would edge towards the factory solution that Ian Kelly suggested
(i.e. not "return self.intersection_kind(...)", but "return
self.factory.create_point(...)" or something similar). Is that so?
-Spencer
More information about the Python-list
mailing list