I am writing a simple graphic editor for a university project using C#.
I created a hierarchy where every type of shape - circles, rectangles, ellipses, ... - are inherited from a base class Shape, it contains a shape color as a protected field.
public abstract class Shape {
protected Color color;
public Shape(Color c) {
color = c;
}
public Color FigureColor {
get { return color; }
protected set { color = value; }
}
public abstract void render(Bitmap canvasToDrawOn);
public abstract void unrender(Bitmap canvasToDrawOn);
public abstract void renderPrototype(Bitmap canvasToDrawOn);
}
The idea is that I want every type of shape to encapsulate it`s geometry part, for example:
public class TwoDPoint: TwoDShape {
Point2DGeometry point;
public TwoDPoint(Color c, Point2DGeometry p): base(c) {
point = new Point2DGeometry(p);
}
public struct Point2DGeometry {
Int32 x;
Int32 y;
public Point2DGeometry(Int32 X, Int32 Y) {
x = X;
y = Y;
}
public Point2DGeometry(Point2DGeometry rhs) {
x = rhs.Abscissa;
y = rhs.Ordinate;
}
public Int32 Abscissa {
get { return x; }
private set { x = value; }
}
public Int32 Ordinate {
get { return y; }
private set { y = value; }
}
}
Ellipse class will encapsulate EllipseGeometry, etc.
Is it a good decision in terms of OO design, and if it is, may be it is the better idea to create a parallel hierarchy of this geometry-only types?