I'm stuck between a rock and a hard place at the moment trying to decided on a good API layout for a .NET COM wrapper project I am working on. This is mainly a design problem and what would work better.
So I have this COM point object:
public class COMPoint
{
internal COMPoint(MyComObject comobject) {}
public SomeCollection Nodes {get; set;}
}
now in order to make point object in my COM object I need to call a few string commands, and this is where I'm having trouble deciding where to point this.
Now I thought about using a POCO that has properties on it then pass it into some kind of factory method, something like this;
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.
}
}
or using a builder pattern, something like:
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.
}
}
}
or a combination of both:
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();
}
}
}
The idea behind using a POCO was so that people could create a point object using the good old
Point point = new Point()
point.Nodes <- Set nodes
pass it around their code and then construct it and get back the one that goes back to the COM object.
Do you think any of these patterns have any credit in this situation?
I'm worried that if I have two different point objects it might confuse the user but then again the builder pattern isn't really that friendly either hmm what to do.
Of course the point object is the simplest object I have to create, there are a lot more objects that are a bit more complicated.
Thanks.