One of the greatest advantages of the builder pattern is that its built object can be immutable. With your second example that would either be impossible, assuming salami()
, pastrami()
, etc. act as standard setters, or it could be inefficient if they each returned a new instance.
JB Nizet points to Guava's Splitter
, which is a good example of the latter case. To your point, Guava developers must have felt that "foregoing seemingly unnecessary complication" was enough reason to tolerate a few extra copies during the creation of customized Splitter
s.