In most of the cases when we write a factory method it is a bunch of if
conditions which can keep on growing. What is the most effective way of writing such a method (with the least if
conditions)?
public A createA(final String id) {
if (id.equals("A1")) {
return new A1();
}
else if (id.equals("A2")) {
return new A2();
}
return null;
}