Ich schreibe einen einfachen Grafikeditor für ein Universitätsprojekt mit C#.
Ich habe eine Hierarchie erstellt, in der jeder Formtyp - Kreise, Rechtecke, Ellipsen, ... - von einer Basisklasse Shape geerbt wird und eine Formfarbe als geschütztes Feld enthält.
Ist es eine gute Idee, jede grafische Form in zwei Teile zu teilen - ihre Geometrie und Rendering-Komponenten?
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);
}
Die Idee ist, dass ich jede Art von Form will `s Geometrie Teil zu kapseln, zum Beispiel:
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 Klasse EllipseGeometry kapseln wird usw.
Ist es ein gute Entscheidung in Bezug auf OO-Design, und wenn es ist, ist es vielleicht die bessere Idee, eine parallele Hierarchie dieser Geometrie nur Typen zu erstellen?