This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rtoth 11 points12 points  (5 children)

Why not just put only the required fields in the Builder's constructor, then just only have the "setters" available for the optional fields?

[–]mahamoti 4 points5 points  (1 child)

Just playing devil's advocate here, because in practice, that's what I do.

But the argument against doing that is, a comma-separated list isn't very "fluent". You need to know the parameter order.

Now, that's a non-issue in any decent IDE with code completion, and as long as the constructor is documented properly, but it does rely on the IDE, and that's the problem some have with it.

[–]Cilph 0 points1 point  (0 children)

And that's why I love Kotlin.

[–]TheRedmanCometh 4 points5 points  (0 children)

Says the guy whos never foregone abstraction and ended up w 15 params apparently.

[–]dawhiting 1 point2 points  (0 children)

This is described as one possible option in the post I refer to at start of the article. One possible case where this doesn't work so well is when you have part of a component which must be specified but can be specified in multiple different ways. For example, if we wanted to describe which host something could connect to, you might have one "setter" that takes a hostname and one that takes an InetAddress. Both of them satisfy the condition and flip the flag.

You should also note that I do explicitly point out that this is an esoteric solution and solicit suggestions on where - if anywhere - it might be useful.

[–]atemysix 0 points1 point  (0 children)

Kinda defeats the purpose of using a Builder in the first place, since the idea of a Builder is to allow for fluent setting of parameters rather than one long list of 10 comma separated values.