I found some overrides methods that not use all the parameters that are in the signature of the method.
ex:
@Override
protected void setSomething(Object a, Object b, Object c) {
this.a = a
this.b = b;
// the parameter c is not used (ignored)
}
Normally the parent class shouldn't be care about how the children will implements the abstract methods.
But in MHO, arguments of a method are to be use, it's very rare when a sub-class implementation doesn't need a parameter, when this happens then probably there's a problem with the design of the interface or with the abstract class.
The base of one function is: inputs -> process of inputs -> output.
Sometimes you need to calculate these inputs, but if you don't go to use some of these inputs in the process of your function, these inputs shouldn't be place as inputs of your function.
You could jump the calculation of these inputs calling an accurate function that use all the inputs, so the accurate function.
The only case where this situation could be acceptable, is when we don't want the behavior of the parent class, so we could write:
@Override
protected void setSomething(Object a, Object b, Object c) {
//Nothing to do
}
Or
@Override
protected void setSomething(Object a, Object b, Object c) {
throw new UnsupportedOperationException(...);
}
Sonar says :
Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.
My Question is: When we override a method we should use all the parameters that are in the method signature?
When I says 'use all the parameters', I try to say that all the parameters that are in the method signature, are really use in the body (implementation) of the method.