The only arguable objection I have is the missing possibility to detect configuration errors from the calling code.
If it is intended to detect errors only by reading the output and implicitly fall back to a default or last sucessfully set value, then this approach is fine.
If there is a need to react to configuration errors individually (e.g. print "No, you won't get a car from me") then I see two possible solutions:
- Use configuration functions that report whether the call succeeded or not, e.g.
Option<Vehicle>orResult. Unfortunately that would make the configuration less convenient than the functions which returnselfas you loose the possibility to directly chain the commands. - Set a testable error flag or
Resultin the builder, optionally have one error flag orResultfor each build step to be able to locate or resolve the error.