top | item 25212129

(no title)

noema | 5 years ago

The main intent of Builder isn't performance, but to avoid a combinatorial explosion of constructors for every possible set of parameters.

discuss

order

lalaithion|5 years ago

So why have constructors for every possible set of parameters?

Why

    VerbalExpression.regex()
        .startOfLine().then("http").maybe("s")
        .then("://")
 .maybe("www.").anythingBut(" ")
 .endOfLine()
 .build();
Instead of

    new VerbalExpression()
        .startOfLine().then("http").maybe("s")
        .then("://")
 .maybe("www.").anythingBut(" ")
 .endOfLine();

szatkus|5 years ago

Both are equally readable to me, but with the builder pattern you have an ability to fork a builder. Cloning objects in Java could be messy.

tpxl|5 years ago

The builder allows you to have immutable objects. While I dislike builders and seldom use them, I dislike mutable objects even more.