No, I understood what you meant by "class" (same as "profession"). And you're correct that there is no point in making each profession a separate class; however, you should create one class that models the concept of a Profession (this is perhaps a better name than my hastily-chosen and ill-thought-out "PlayerClass," above).
Anyway, responding to your newest post will allow me to restate my original suggestion (which still applies even in light of all this new information), so here we are:
Quote:
Ive completed v1.0 of the getClasses function, can you tell me if i got it right?
This function is generally poor and redundant. The first issue is the name. StatBlock::getClasses() doesn't return a list of classes, it returns a list of class names. So, if this is really desired, the function should be called getClassNames(). The second issue is that the function is poorly designed, as it places
responsibility for naming classes with the StatBlock and not with the profession class itself. Finally, it is redundant because StatBlock::ClassList itself provides exactly the same information.
What I suggested before, and what I continue to suggest now, is that you have:
class Profession{ public: Profession(const std::string &name,int baseHP,int baseMP); //...and so on. const std::string &getName() const;};
This class models the concept of a profession, including that professions display name, base stats, abilities (can it cast clerical spells, mage spells, turn undead, and so on).
StatBlock::ClassList becomes a vector<Profession>. You can initialize this however you like, from a file, or from code:
StatBlock::ClassList.push_back(Profession("Warrior",100,25));StatBlock::ClassList.push_back(Profession("Mage",50,250));StatBlock::ClassList.push_back(Profession("jpetrie",std::numeric_limits<int>::max(),std::numeric_limits<int>::max()));
And so on.
This makes getClasses() redundant, as you can just iterate through ClassList and call the Profession's getName() method, or
whatever other method you want to call that exposes the functionality you need (such as what the abilities, HP, et cetera of that profession are). This is actually more flexible and maintainable, and overall a better object model for the system.
The player object itself can be assigned a Profession instance that is a copy of, or a reference to, an element in StatBlock::ClassList. That way you can represent the profession of the player without redundant information.
The idea of keeping everything in
one class
seems simpler, but its actually more brittle and generally poorer design in 99% of the cases. It's possible that your "stat block" class might be the same as what my "profession" class is supposed to be, but in that cases I would argue that your name is poorly chosen, and that getClasses() is an inappropriate member function... but that all depends.
Can you explain your system in a large context? What
is a StatBlock, what does it represent, and how is it used in your system? How do you represent the player? And so on. It will help focus our discussions.
[Edited by - jpetrie on May 14, 2007 1:38:25 PM]