I was wondering how to make Builder with additional parameters more elegant:
what I have: an object with a name, identifier, age.
I have a difficult condition for including age, and I would like to send it to the developer for the success of this condition, but I would like it to be an elegant single liner with one parameter.
what i still have:
Builder.name("name").id("id").age(age, complexCondition).build();
or
Builder builder = Builder.name("name").id("id");
if(complexCondition){
builder.age(age);
}
Are there any better options? I would like to resolve a condition where I have this without a constructor without an add-in and without recoding for each check of complex conditions.
upd: I'm looking for a solution without:
a) passing complexChecks or boolean to builder - not his job of validation by definition
b) without adding 3 lines for each test condition inside the method calling builder