I have an attribute in my car class called VehicleType.
Using an enum, I could list the different types of cars that exist and not allow any other type to be hard written in.
Problem is, if I have to GET the attribute from somewhere else, I will GET a numberical value, and not the string literal I saved.
What should I use here?
class Hero
{
public string faction;
public string name;
public string herotype;
enum HeroType
{
Agility,
Strength,
Intelligence,
}
}
You could create an abstract base class
and then derive your heroes from that:
Common stuff would be handled and coded in the base class, those things specific to a hero type in the actual hero class.
Using this OO approach, you can save yourself from having to write, code, maintain a lot of
if....then.....elseorswitchstatements in yourHeroclass – the differences are handled by the fact of having different types for each type of hero.