我想通过面向对象的方法实现绘制不同的图形,目前我先写了一个绘制直线的类,请朋友指点一下写的对不对,谢谢!
public abstract class Shape
{
public abstract void drawShape(Graphics graphic,Pen pen);
public Point firstPoint;
public Point lastPoint;
}
public class Line : Shape
{
public Point firstPoint;
public Point lastPoint;
public override void drawShape(Graphics graphic,Pen pen)
{
//throw new Exception( "The method or operation is not implemented. ");
Graphics g = graphic;
g.DrawLine(pen, firstPoint, lastPoint);
}
}
public class DrawShape
{
public DrawShape()
{
}
public static Shape getShape(string strShape)
{
switch (strShape)
{
case "Line ":
Line line = new Line();
return line;
default:
return null;
}
}
}
------解决方案--------------------public static Shape getShape(string strShape)
{
switch (strShape)
{