In my legacy code I have a a concept of attribute/value pairs.
Each attribute/value has some arbitrary meaning in my system. So, my interface has the methods getValue() and setValue(). Each of these does some specific business logic based on what the attribute means in my system.
This works pretty well, but I am running into some issues.
The first is my mapping tends to look something like this:
if (name == "name1") return thisAttributeImplementation();
which is ugly and easy to screw up typing…
The second is that these AttributeImplementations need to know the name of their attributes, but they don’t unless I provide it as a static member, or pass it into the constructor, both of which are ugly.
It seems like enums would be a good solution to both of these problems, but I’m having trouble working out the logistics. What should the enums look like in order to associate a string with an object? How should I iterate through the enums to find the appropriate one? How should the objects themselves gain knowledge of the string they’re associated with?
Something similar to this works correct?