I have a base class Shape, and drived classes Line Segment, Arc, B-spline,... I want to find the intersection point between these shapes. I would like:
Shape* a = new LineSegment();
Shape* b = new Arc();
bool did_intersect = a->Intersect(b);
I don't like this design in Intersect:
bool LineSegment(Shape* s) {
Arc* arc = dynamic_cast<Arc*>(s);
if (NULL != arc)
return LineSegmentArcIntersection(this, arc);
BSpline* bspline = dynamic_cast<BSpline*>(s);
if (NULL != bspline)
return LineSegmentBSplineIntersection(this, bspline);
...
}
So, What design pattern is best suitable with this context?