I like using enum class to avoid hard coded values as much as possible but it's a little bit more complicated when it comes to strings. I have a design I'd like to share that I feel is a little bit bulky and I would love some ideas on how to simplify it.
class StringDefinition
{
private:
StringDefinition(const std::string &def);
public:
bool operator==(const StringDefinition&rhs) const;
public:
static const StringDefinition StringDefinitionOne;
static const StringDefinition StringDefinitionTwo;
static const StringDefinition StringDefinitionThree;
public:
std::string ToString() const;
private:
string stringDef;
};
StringDefinition::StringDefinition(const std::string &stringDef)
{
this->stringDef = stringDef;
}
const StringDefinition StringDefinition::StringDefinitionOne("One");
etc...
All ideas and comments are welcome.
Edit: I am not using string literals because it does not force the developer to use a value from a definition list. They can still hard code a string even when you expect them to use your string literal. If I'm doing something crazy, I'd love some constructive criticism rather than just down voting the question.