this is a question about programming best practices, I didn't know how express the question in the Title, sorry, here we go.
I had a method in a Manager, or Controller, this way:
public boolean myMethod(Param1 param1);
And, because a change in the application, I had to redefine it like this, because it calls to other method which needs param2 and param3:
public boolean myMethod(Param1 param1, Param2 param2, Param3 param3);
Now I realize that the method with 3 params "always" (for now, maybe in the future there is a change and I need to call it with non-null params) will be called with param2=null
and param3=null
, so in the implementation of 1st method I did:
public boolean myMethod(Param1 param1) {
return this.myMethod(param1, null, null);
}
public boolean myMethod(Param1 param1, Param2 param2, Param3 param3) {
/* Call to other methods that is needed to pass it param2 and param3 */
}
So the call to the method of the Manager, and the original way, is,:
boolean isTrue = myManager.myMethod(param1);
This is one option, the other option is to pass the null params from the call:
boolean isTrue = myManager.myMethod(param1, null, null);
And let only one method in my Manager:
public boolean myMethod(Param1 param1, Param2 param2, Param3 param3);
So, the real questions are: What is the best way to do this talking about best practices? Is it wrong if in the implementation of tha Manager I overload a method and call it with null params?
Thanks in advance!
Greetings.