I have a method which is implemented as below
public void setAttributes(Data d) {
Model m;
String type = d.getType();
if (type.equals("TYPE1")) {
m.setType(type);
m.setDuration(d.getDuration())
m.setBenefit(d.getBenefit())
m.setPermission(d.getPermission());
} else if (type.equals("TYPE2")) { /* Here we wont be having duration, benefit */
m.setType(type);
m.setLab(true)
}
}
This doesnot look scalable because in future if some more TYPES comes, then we need to keep adding if else blocks. Is there any way I can refactor this. Note: Attributes will be different based on types.