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.
|
buildXXXisbuildXXXparts builder. in this case, the canonicalbuildmethod is represented by thegetPizzamethod. By the way, the second example is more familiar there. - vp_arthnew 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