public class Person
{
protected Map<String, String> data;
public String getString(String key)
{
return getData().get(key);
}
public void setString(String key, String val)
{
getData().put(key, val);
}
}
I want a flexible object that could change and have new fields eventually, or fields eventually go unused based on a users needs.
Say at first the user just needs the basic fields: Name, Age, Height.
But later on another user needs to capture: Hair Color, Eye Color, & Ethnicity, on top of the already used fields
Would using a String, String map be viable?
I could create all the fields
int age;
int height;
String name;
String eyeColor;
...
But my "Person" could only extend so far with just these fields. Not sure what the best practice is for this, or if the string map is the route go. Any insight would be appreciated.
Well the project is a crud application that is used for insurance purposes. Each branch company stores drivers differently and uses driver information differently, as what data fields are captured and what are not. Some capture how many accidents someone has been in, some do not. Some require years driving, and a driver grade, while some do not. I wasn't sure the best design practice to make a flexible object, that extends to the cases of each branch company, without creating multiple driver extended objects, because everytime a new carrier comes in, i need a new object for their needs
Using:
Java JSP/Struts2 MySQL as DB.