I`m currently working out the design for simple graphic editor, who support trivial operations for two-dimensional and three-d shapes.
The point is, I want to render prototype of these shapes, as MsPaint does. And at the moment it is rendering I need to store somewhere pixels from the canvas which get covered by prototype, just in case when prototype changes to restore their state on the canvas. So, I want all my shapes to support this kind of buffering (Graphic Operation is the base class for all rendering operations):
public abstract class Shape: GraphicOperation {
protected List<SomePoint> backup;
public Shape(Color c): base(c) { }
public Color FigureColor {
get { return color; }
protected set { color = value; }
}
public abstract void renderPrototype(Bitmap canvasToDrawOn);
}
The main idea is that in terms of OO design it would be great to provide the support of the buffer on base class (Shape) level, I mean for TwoDShape and ThreeDShape classes this list must be initialized in different way - for TwoDShape with TwoDPoint instances, and for ThreeDShape with ThreeDPoint instances.
But to do this, SomePoint must be base class for both two-dimensional point and three-dimensional point classes. Is it acceptable in terms of OO to derive both these classes from single base class?
May be there are too many words, but I just wanted the problem to be clear for everyone.
Edit: btw, is this the good idea to derive point classes from their king of shapes? I personally see no other options, but may be it would be better if I derive it directly from shape? Now it is:
public abstract class TwoDShape : Shape {
protected List<SomePoint> backup;
public TwoDShape(Color c) : base(c) { }
}
public class TwoDPoint: TwoDShape {
//...
}
and the same is for ThreeDPoint.