I have the following classes:
public Employee : IPerson
{
public string Name { get; set; }
}
public Manager : IPerson
{
public string Name { get; set; }
}
at run-time, I may need to:
var person = new Manager();
or possibly:
var person = new Employee();
and then:
string name = person.Name;
at some point. I'm currently using Activator.CreateInstance(), but was wonder if approaching the problem incorrectly? The type of class is dictated at run-time so I have no advanced noticed.
I was hoping to avoid something like:
string externalValue;
var person;
switch (externalValue)
{
case "Manager":
person = new Manager();
break;
case "Employee":
person = new Employee();
break;
}