I currently have the following:
public abstract class CharacterClass
{
public abstract Attribute FirstAttributeBonus { get; }
public abstract Attribute SecondAttributeBonus { get; }
protected Attribute[] attributeBonuses; //2 attribute bonuses, which add 10 to the attributes stored in the array.
protected SKill[] majorSkills; //Major skills for class begin at 30.
protected Skill[] minorSkills; //Minor skills for class begin at 15.
protected IDictionary<int, Character> characterList; //List of characters who apply to this class specifically.
public CharacterClass()
{
}
}
With the idea in mind that whichever class I create will inherit from this base, and also inherit the classes fields as well. For example, one class could be Warrior; the other could be Battlemage, etc.
Is this the right way to perform such a design, while having the derivative constructors initialize the fields? Or is it better to write the classes out without them inheriting these fields?
Edit:
I forgot to mention that all derivatives will be singletons, and I’m changing the name of Class to “CharacterClass”, to avoid confusion.
You absolutely need to get a hold of the book called Head Start Design Pattern. You don’t need to read the entire book: its first chapter describes the design pattern you are looking to implement.
Basically, you want your Character class to have interfaces that call classes that hold your implementation code such as the skill classes, attribute classes and all the other ones you’ll add later. That way, you can add new types of skills and attributes and you’ll also be able to modify those at runtime. You DON’T want the character class to hold all the possible implementations. For what you’re trying to do, you want to favor object composition instead of inheritance.
Take 20 minutes to read the first chapter: http://oreilly.com/catalog/9780596007126/preview