I have several classes that all inherit from the same Shape
class. When I create a new shape I want it to be of a random shape. The way that I thought to do it is to create a list that will hold links to all the constructors, and when I need to create a new shape I'll get a random constructor from the list and use it to construct my shape. I've tried to create the list in the fallowing way, but I get errors:
List<Action> constList = new List<Action>();
constList.Add(SShape());
constList.Add(OShape());
constList.Add(LShape());
The Shape
constructor is defined as:
class Shape
{
public Shape(PlayGrid grid, Color color)
{
...
}
...
}
And each sub shape's constructor is defined like:
class IShape : Shape
{
public IShape(PlayGrid grid, Color color) : base(grid, color)
{
...
}
...
}
What is the correct way to construct the list, and what is the way to use the constructors from the list?
The contractors also need to get parameters that change between different shapes.