I know what Visitor Pattern is and how to use it; this question is not a duplicate of this one.
I\'ve got a library where I put most of the reusable code I write,
There a many possible solutions, but you could do this, for example: Start new hierarchy, which renders Shapes
in a specific Context
:
// contracts:
class RenderingContext {
public: virtual void DrawLine(const Point&, const Point&) = 0;
// and so on...
};
class ShapeRenderer {
public: virtual void Render(RenderingContext&) = 0;
};
// implementations:
class RectangleRenderer : public ShapeRenderer {
Rectangle& mR;
public:
virtual void Render(RenderingContext& pContext) {
pContext.DrawLine(mR.GetLeftLower(), mR.GetRightLower());
// and so on...
}
RectangleRenderer(Rectangle& pR) : mR(pR) {}
};