Apologies for the awful title, I couldn't think of a better way to phrase it.
Essentially I have an abstract base class Category
and whole host of derived classes inheriting from that. Is it possible to do something along the lines of:
List<Category> catList = new List<Category>();
catList.Add(new Category(myCategoryTypeString));
Where myCategoryTypeString
will always be the name of one of the derived classes and have it instead create a new object of that derived class (presumably using a switch on the string to determine which class to use).
So that something along the lines of:
catList.Add(new Category("Engineering"));
Would add a new object of Engineering : Category
type to the list?
If that is possible how would one go about doing this? My abstract class is defined thusly:
abstract class Category
{
private string line;
private bool ToChallenge;
private string[] columns;
private int oppLevel;
protected Category(string line)
{
this.line = line;
columns = line.Split(',');
}
public abstract bool IsAnomoly();
public abstract void CategoriseAnomoly();
public abstract void WriteLine();
}