Luca Fülbier Luca Fülbier - 2 months ago 5x
Java Question

Implementing the builder pattern

I have seen two popular methods of implementing the builder pattern:

// 1. The build() approach
Product p = builder.part1()

// 2.The constructor approach
Product p = new Product(builder);

Which of these is preferable?


1st one is the way to go...

if you use the 2nd choice then doing this:

Product p = new Product(builder);

will add dependencies to the Product class..

that means the Product class needs now at least a constructor with the parameter builder