Hello,
I am currently working on a strategy pattern. It consists of an abstract base class that declares some functionality, and some derived classes that implement that functionality. My problem is that only a specific set of derived classes is allowed. Coming from a Java background, I have tried to implement that in the following way:
I am getting the error that "an instance of the abstract class or interface Edge could not be created". Removing the abstract keyword from the class declaration gives the error "Edge does not contain a constructor that takes 1 argument".
Is there any way to implement that pattern in C#?
best regards
I am currently working on a strategy pattern. It consists of an abstract base class that declares some functionality, and some derived classes that implement that functionality. My problem is that only a specific set of derived classes is allowed. Coming from a Java background, I have tried to implement that in the following way:
C#:
public abstract class Edge
{
private string name;
public static Edge TOP_LEFT = new Edge("TOP_LEFT")
{
public PointF Coordinate(RectangleF area)
{
return new PointF(area.X, area.Y);
}
}
private Edge(string name)
{
this.name = name;
}
public abstract PointF Coordinate(RectangleF area);
}
Is there any way to implement that pattern in C#?
best regards