I am working on existing code to enhance the functionality.
In existing code I saw there are multiple constructors with string parameters. like
public class A {
public A(String a){
}
public A(String a, String b){
}
public A(String a, String b, String c){
}
}
While enhancement i found that i need to add another string parameter to the constructor.
However this seems to be problem, there could be another enhancement in that i have to add anther string.
I want to avoid such scenario.
What could be the best design to avoid such scenario?
Is good solution is to use HashMap?
It’s not really clear what problem you’re trying to solve, but you might want to consider encapsulating the parameters in another class – perhaps one which is mutable, following the builder pattern. That would leave you with something like:
(You could even have a
buildFoo()method inFooParamsto keep the whole thing fluent.)