在我的winform項目中,我有一些圖形模型類:Rectangle
,Assosiation line
和Text
。 實施例:取決於對象類型的創建模式
public class Rectangle
{
public short Id { get; set; }
public short Zindex { get; set; }
public Color BackColor { get; set; }
public bool Selected { get; set; }
public Size Size{ get; set; }
}
,共同Inteface IPathBuilder
與類生成圖形pathes每個模型:RectangleGraphicPathBuilder
等。示例:
public class RectangleGraphicPathBuilder : IPathBuilder
{
protected override GraphicsPath Build(IShape inShape)
{
var shape = inShape as Rectangle;
var newPath = new GraphicsPath();
newPath.AddRectangle(new Rectangle(shape.Location.X, shape.Location.Y, shape.Size.Width, shape.Size.Height));
return newPath;
}
}
,我需要使用調用這些助洗劑而形狀一些圖案在集合迭代中。喜歡:
forech(IShape shape in shapeColection){
var path = IPathBuilder.Builder(shape);
}
我會很樂意收到關於它的任何提示。
這看起來像複製對象,而不是構建新對象......如何在IShape中放置Copy或Clone方法,並讓每個類以其特定方式實現它? – 2014-10-16 13:26:44
你的意思是在模型中添加PathGenerator方法?我想這個模型只包含它的參數:顏色,大小等等,並且能夠顯示我想爲特殊服務IPathBuilder提供的圖形方式。 – 2014-10-16 13:28:12