You could create a factory class:
public class LineFactory
{
public Line Create(<parameters here>)
{
//create and return a Line object
}
}
The factory could also be static
, but that could hinder testability.
Note that this solution doesn't let you extend the Line
class as inheritance would. To do that you would need to return a MyLine
class which would embed a Line
object along with the additional properties you'd want MyLine
to have.
public class MyLine
{
private Line _theBoringOriginal; // composition: "has-a" (vs inheritance "is-a")
public MyLine(Line line)
{
_theBoringOriginal = line;
}
public foo SomeProperty { get; set; }
}
If it's just methods you want to extend the Line
class with, you don't need a new class, you could just write extension methods in a static class:
public static foo DoSomethingCool(this Line line, <parameters here>)
{
// whatever
}