I'm having a class in which many parameters are being added as per new api integration.
For example, earlier I had a class with 4 parameters:
Integer a;
String b;
Map<String, String> c;
List<Integer> e.
So the constructor was:
public SampleClass(Integer a,
String b,
Map<String, String> c,
List<Integer> e)
{
this.a = a;
this.b = b;
this.c = c;
this.e = e;
}
Several teams have integrated with my API using this constructor in their code. After sometime, there was a new parameter added to this class. i.e.
Double d;
So I added a new constructor:
public SampleClass(Integer a,
String b,
Map<String, String> c,
List<Integer> e,
Double d)
{
this.a = a;
this.b = b;
this.c = c;
this.e = e;
this.d = d;
}
And I marked the previous constructor as deprecated. I did not remove the previous constructor because if removed, the client's code would break.
As the new parameters are getting added, I now have constructors with 5 parameters.
Is there a best practice on how the constructors should be deprecated/removed, so that this type of scenario does not occur?