Consider that code:
FancyClass c = new FancyClass();
s.setParameter(value);
s.setParameter2(value2);
//a lot of parameters
It is really naive, so we can use a builder pattern:
FancyClass c = new FancyClassBuilder().setParameter(value).setParameter2(value2).build()
It is okay, but what if we have to use a lot of setters during a program?
s.setParameter(value)
s.setParameter1(value)
s.setParameter2(value)
s.setParameter3(value)
//more and more...
It will be more efficient and less boilerplated:
s.setParameter(value).setParameter1(value).setParameter2(value)
.setParameter3(value)
Looks more okay and it allows programmer not do this action: (i hate it):
s.setParamter()
// a lot of doing smth
s.setParameter2()
even there is no neccessary to put this setters away (because it is a some legacy issue, somebody just tap the enter twice and someone type in a other code...
What if...
@SetterChain
class MyFancyClass {
public void setParameter(Parameter p) {}
public Parameter getParameter(Parameter p) {}
public void setParameter2(Parameter p) {}
public Parameter getParameter2(Parameter p) {}
}
//somewhere else...
MyFancyClass s = new MyFancyClass()
//a long time ago
s.set().parameter(value).parameter2(value); //and more and more...
Cool stuff or no? Is this solution would significally increase a code quality or not and its a wreck and why?