TITLE: Polymorphic drawing devices PROBLEM: sally@cattell.psych.upenn.edu (Sally Davis) I have geometric classes for lines, arcs, bezier curves, ellipses, etc. I also have several formats in which I want to output various coordinates, feedrates, colors, linetype, etc. For example, I need to output to CAD programs, CNC machines, and plotters. So, how would I best design a class hierarchy that elegantly outputs the information? RESPONSE: p j l @graceland.att.com (Paul J. Lucas), 7 Dec 94 class AbstractRenderEngine { public: virtual void Line( int x1, int y1, int x2, int y2 ) = 0; virtual void Arc( int x, int y, int start, int end ) = 0; // ... }; class CAD_RenderEngine : public AbstractRenderEngine { public: // override all pure virtuals }; class CNC_RenderEngine : public AbstractRenderEngine { public: // override all pure virtuals }; class Plotter_RenderEngine : public AbstractRenderEngine { public: // override all pure virtuals }; class Renderer { public: Renderer( AbstractRenderEngine *e ) : engine( e ) { } ~Renderer() { delete engine; } Renderer& operator=( AbstractRenderEngine *e ) { delete engine; engine = e; return *this; } AbstractRenderEngine* operator->() { return engine; } private: AbstractRenderEngine *engine; }; /* This allows you to have a single Renderer class into which any RenderEngine cab be "plugged" and can even be changed on the fly at run-time. */ [ We use a design similar to the above in the graphics unit in guide. It encapsulates the differences between rendering to the screen using X, to postscript files, etc. -adc ]