I have a database table that contains a column named type. For every row in my database column I have to create an object depending on the type. At the moment I use if else statements for that:
if (type.equals("object1")){
Object1 object1 = new Object1();
}
else if (type.equals("object2")){
Object2 object2 = new Object2();
}
Somewhat nicer would be to use an enum, as the number of types is limited but is there a possibility to let the creation of an object depend on the value of the String?
I'm open to suggestions that might solve my problem in another way than I am trying to.