我正在制作一个绘画程序,可以在其中绘制矩形/椭圆形。在该程序中,我可以移动/调整大小,但也可以保存它们。
我的问题是,现在我需要制作一个访客模式(调整大小/移动并保存),但是我不知道应该从哪里开始。
这些是我目前使用的方法:
public abstract void ResizeShape(PosSizableRect posSizableRect, float lastX, float lastY, float newX, float newY);
public abstract void MoveShape(int x, int y);
private void Write(List<Shape> shapes, StreamWriter streamWriter, string tabs = "")
抱歉,由于我的声誉而无法给您照片...
public interface IShape
{
void Resize(PosSizableRect posSizableRect, float lastX, float lastY, float newX, float newY);
void Move(int dx, int dy);
void Write (StreamWriter writer, string tabs ="");
void AcceptVisitor(IVisitor visitor);
}
public interface IVisitor
{
void Visit(IShape shape);
}
多数民众赞成在接口,现在实现(一个例子)
public class MoveVisitor : IVisitor
{
private int dx;
private int dy;
public MoveVisitor(int dx, int dy)
{
this.dx = dx;
this.dy = dy;
}
public void Visit(IShape shape)
{
shape.Move(dx,dy);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句