In the wiki template description in the Builder class, the previously generated buildXXX () methods are used to build different objects with the same field values. But if every time you need to create fields with different values, it is logical to pass the values ​​as parameters.
The question is whether the pattern allows the transmission of field values ​​as parameters, if not, then what is the most correct thing to do in such cases? Especially with a large number of required parameters.

  • one
    In fact, the very essence of Bulder is to build an object piece by piece - rjhdby
  • one
    Methods in the wiki are not named very well. buildXXX is buildXXX parts builder. in this case, the canonical build method is represented by the getPizza method. By the way, the second example is more familiar there. - vp_arth
  • Well, yes, the names of the methods are a little confused. But I understood from the rjhdby answer that there is nothing that prevents the transfer of parameters to them? - Tariel
  • one
    Just look at the second example. Sure you may. - vp_arth
  • As far as I have seen, a builder is usually used to build complex objects in stages. For example new SomeObjectBuilder(). withName(""). withCount(""). build(); new SomeObjectBuilder(). withName(""). withCount(""). build(); Perhaps this builder has a dozen such "with" methods. But we call only those that we need. A build can check if all necessary values ​​are set and throw an error if not all. Without a builder, you would have to make a bunch of different constructors to urinate, set different combinations of parameters and get an error if necessary. - IL Mare

0