Luca Fülbier Luca Fülbier - 1 year ago 49
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download