Hello. I have the following function: public BaseClass SpawnClass( ObjectType type ) { BaseClass retval = null; float X = 5; float scale = 0.3429f; switch(type) { case ObjectType.Class1: { retval = new Class1(X,scale); break; } case ObjectType.Class2: { retval = new Class2(X,scale); break; } case ObjectType.Class3: { retval = new Class3(X,scale); break; } } return retval; }
I have about 11 classes but I didn't want this to get too long. This works, but it's very ugly. Is there a better way to do this? I've thought about the "Gang of Four" design patterns, but I'm not sure if they would be less ugly. I noticed the TypeConverter class, but I don't know how to use it. Any suggestions?
I love to program!