TITLE: Concrete mixin-inheritance example PROBLEM: clarke@ses.com I was going over a recent posting you made to clc++. It contained this pattern: ONE SERVER (single concrete implementation derived from | the virtual base) | ONE INTERFACE (virtual base) | MULTIPLE CLIENTS ( (abstract) classes derived from the virtual base) | MANAGER (Most derived class) And this code snippet: class Server { .. }; class Client1 : public virtual Server { .. }; class Client2 : public virtual Server { .. }; ... class ServerImpl1 : public virtual Server { .. }; class ServerImpl2 : public virtual Server { .. }; ... class Master : public ServerImpl1, public Client1, public Client2, ... { Master (args) : ServerImpl1(args1), Client1(args2), Client2(args3) .. }; Would it be possible to get a domain-specific tiny example of this, perhaps in the drawing or GUI arena (most likely to be understood by a wide audience). RESPONSE: John Max Skaller , 31 Jan 95 Hm. Lets try: struct Screen { // Interface virtual void putPixel(int x, int y, int colour)=0; virtual float scaleX()const=0; virtual float scaleY()const=0; }; struct PC_Screen // Server for a PC : public virtual Screen { PC_Screen(int VesaMode) { .. } .... float scaleX()const { .. } float scaleY()const { .. } private: // data here }; struct Circle : public virtual Screen { // Client void putCircle(int x, int y, int radius, int colour) { /* stuff to draw a circle */ } }; struct Line : public virtual Screen { // Client void putLine(int x, int y, int x2, int y2, int colour) { /* stuff to draw a line */ } }; struct Rectangle : public virtual Screen { // Client void putRectangle( ..... ) { /* stuff to draw a Rectangle */ } }; struct PC_Graphics_Console // Master : private PC_Screen, public Circle, public Line, public Rectangle { PC_Graphics_Console( int mode) : PC_Screen(mode) {} }; Here, the interface "Screen" can be used to write pixels, it can _also_ tell its clients how much to scale in the X and Y directions to get the visual aspect ratio correct. (Pixels do not have to be square :-( Also, this is used to account for high or low resolution -- i.e. to normalise the coordinate system. The clients have to draw shapes that look the same relatively, on any screen. The code for drawing will work for _any_ PC screen mode, a Unix screen, or anything else. The actual representation is fixed in the Master object "PC_Graphics_Console". From this_single_ object, you can upcast to get a pointer to a Line, Circle, and Rectangle drawing class which will work together, sharing the same screen, and the same aspect ratio and scaling factors. Or, you can write representation dependent code using the master directly (not shown, but I could add code to do PC specific special effects like palette rotation). This buys you "free" use of the Standard interface with extensions. BTW: In practice, the server will probably use delegation to a separate device driver object, to obtain even greater flexibility (like dynamic mode switching?) The main point, of course, is to separate the interface and implementation, and then bind them togther later in the most derived class. Notice all the drawing routines are abstract because the depend on the unimplemented putPixel() method. It is the master which fill in that routine by mixin in the PC_SCreen implementation. BTW2: My graphics library does not work exactly like this, but I'm using this _kind_ of technique to write a game which I hope will be easy to port.