public class COMPoint
{
internal COMPoint(MyComObject comobject) {}
public SomeCollection Nodes {get; set;}
}
现在为了在我的COM对象中创建point对象,我需要调用一些字符串命令,而这正是我在决定指向何处时遇到的问题。
现在我考虑使用一个具有属性的POCO,然后将其传递到某种工厂方法中,类似这样的方法;
public class Point
{
public SomeCollection Nodes {get;set;}
}
public class GeometryFactory
{
public GeometryFactory(MyComObject comobject) {}
public CreateCOMPointFrom(Point point)
{
// Do COM work here and return new COMPoint.
}
}
或者使用生成器模式,例如:
public class COMPoint
{
internal COMPoint(MyComObject comobject) {}
public SomeCollection Nodes {get; set;}
public class Builder
{
public Builder(MyComObject comobject) {}
public SomeCollection Nodes {get; set;}
public COMPoint Create()
{
// Do COM work here and return new COMPoint.
}
}
}
或两者的结合:
public class COMPoint
{
internal COMPoint(MyComObject comobject) {}
public SomeCollection Nodes {get; set;}
public class Builder
{
public Builder(MyComObject comobject) {}
public SomeCollection Nodes {get; set;}
public COMPoint Create()
{
// Do COM work here and return new COMPoint.
}
public COMPoint CreateFrom(Point point)
{
// Set builder properties and call.
this.Create();
}
}
}
Point point = new Point()
point.Nodes <- Set nodes
将它传递给他们的代码,然后构造它,并返回返回到COM对象的代码。
我担心,如果我有两个不同的点对象,它可能会混淆用户,但再次建设者模式是不是真的很友好,嗯,怎么办。
当然,point对象是我必须创建的最简单的对象,还有很多更复杂的对象。