Hi,
I am working on a basic application which should list some objects, for the sake of this example lets assume its the two nice objects man and woman, both descendants of human.
Even though the objects should of course not be aware of the UI, there are certain things which are shared among these objects. Let me give you a simple example (excuse the stereotypes, please):
Human
- Name: Hans
Woman: Human
- Habit: Shopping
- Name: Claudia
Man: Human
- Sport: Golf
- Name: Karl
Now, in the UI, if I list the properties, I of course want to databind them to the values of the class. But I also want to change the values and labels for according to language. Using ressource strings is not practical, as there are too many different properties and labels.
One idea I had was to use my own class, StringProperty, instead of a pure string. Depending on language, I would then fill the property and label, the UI would look like this:
Man (GER)
Sport: Fußball
VorName: Hans
Woman (GER)
Gewohnheit: Einkaufen
VorName: Claudia
Man (ENG)
Sport: Football
FirstName: Hans
Woman (ENG)
Habit: Shopping
FirstName: Claudia
Now there is a downside of this approach. Lets assume I have 100 objects of type man. I know they will all be in english, there is never a mixed collection of GER + EN. In that case, I save the label "Sport" value 100 times, instead of one time. I could wrap one static class property and use object properties as pure getters.
There I get another problem: If I use the StringProperty on a man and on a woman, the Label on the one class must be "always" Sport, on the other always "Habit". So I have 100 men, 100 woman, 100 string properties with Label "Sport" and different values, and 100 woman properties with label "Habit" and different values.
Now its a small application, I am talking about approx 200 main objects, with approx 20-30 properties. This means, if I use the brute force approach, I would have 200x20 = 4000 labels strings, instead of 1 x 20 label strings.
Are there any good ways to solve the problem, any best practice, or GOF pattern I can use? Also keep in mind, because the raw amount of data is really little, I want to use simple serialization to store the objects, not sure how this behaves in case of exotic "static lookups based on reflection" or other stuff which crossed my mind.
Thanks for any tips, Chris
PS: I want to avoid having to code UI elements manually in a lot of places. A control for a StringProperty will always have a label and show the string value next to it, so it would be really nice to use the same data container for it...
PPS: One other idea I just had seems like it will cause to many classes. Its the interface and flat subclass approach. In that case, I would have one Interface ILabeledStringProperty and create, for the example above, the following structure:
GerSportsPropClass
EngSportsPropClass
GerHabitPropClass
EngHabitPropClass
GerNamePropClass
EngNamePropClass
All implementing the ILabeledStringProperty, where I bind to in my UI. When newing up the objects, I would decide which language I am in, and use the appropriate class, having the label as a const string property. Seems feasible, but not sure if nearly "best practice"...