I am sure that I was busy with a lot of castings and such in this code below. It seems like there should be a smoother path. Basically, I'm trying to use the builder (CreateNewPattern) method to process new objects of a passed subclass type (using the CreateNewCircularPattern and CreateNewLinePattern methods). Currently, I only have two subclasses like CircularHolePattern and SingleLineHolePattern, which are inherited from HolePattern, but I expect more as my application grows.
Is this a place to use delegate or lambda? He does not know anything about them, so please be as specific as possible with the code suggestions.
private CircularHolePattern CreateNewCircularPattern()
{
var CreatedPattern = CreateNewPattern(typeof(CircularHolePattern));
return (CircularHolePattern)CreatedPattern;
}
private SingleLineHolePattern CreateNewLinePattern()
{
var CreatedPattern=CreateNewPattern(typeof(SingleLineHolePattern));
return (SingleLineHolePattern)CreatedPattern;
}
private HolePattern CreateNewPattern(Type PatternTypeToCreate)
{
var NewHolePattern = (HolePattern)Activator.CreateInstance(PatternTypeToCreate);
NewHolePattern.PatternName = "Pattern #" + (HolePatterns.Count + 1).ToString();
this.AddPattern(NewHolePattern);
this.SetActivePattern(NewHolePattern);
return NewHolePattern;
}