We're writing an SDK for a CAD program and have run into a slight disagreement regarding a specific type of function (not just disagreement between different people, also disagreement between my two brain-halves).
Imagine there's a lot of classes for specific curve types (ellipse, circle, arc, line, bezier etc.). All of these classes can be represented by a Nurbs curve. So should we put the Circle->Nurbs function on Circle:
public NurbsCurve Circle.ToNurbsCurve()
{
// Return a circular NurbsCurve or null if the Circle is invalid.
}
or should it be a static on NurbsCurve:
public static NurbsCurve NurbsCurve.CreateFromCircle(Circle)
{
// Return a circular NurbsCurve or null if the Circle is invalid.
}
I think I'd go for the first (e.g. on the shape classes, maybe even with a common base class or interface like IConvertibleToNurbsCurve
), because this makes it easier if you add other shapes later which are also convertible to a NurbsCurve
.
The NurbsCurve
seems to be less specialized and therefore should not "know" about the more specialized types IMHO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With