Suppose we have a BaseModel
, which has a type
enum, and derived models with same constructor signatures to each other, whose implementations are like :
public DerivedModelJ(Object arg1, ..., Object argN) {
super(Types.TypeJ, arg1, ... argN)
}
Now suppose that, when we use them, we want to hit a method that will return the right model, but don't want to sort through it on that side (let alone wherever else you might end up needing it in the future).
Would it be a code smell to be like:
public static BaseModel Create(Types type, Object arg1, ..., Object argN) {
HashMap<Types, Class> typesDict = new HashMap();
typesDict.put(Types.Type1, DerivedModel1.class);
//...
typesDict.put(Types.TypeM, DerivedModelM.class);
return typesDict.get(type).newInstance(arg1, ..., argN);
}
on BaseModel
?