This one is straight from Effective java 2. I’m not sure what does this statement from Item 2 means
The Builder pattern is flexible. A single builder can be used to build
multiple objects. The parameters of the builder can be tweaked between
object creations to vary the objects.
I’m not able to come up with an example to do this.
Please help me understand this with an example.
This blog post provides a good example of builder objects being used by the JavaFX 2 API.
The builder object is responsible for constructing a valid object but The object is not constructed until you call the
build()method. This means the same builder can be used multiple times to construct completely different objects.Example:
This can be done as many times as you want to create different objects. Just to re-iterate the point that the object is not created until the
build()method is called, consider that you could do the following:which would result in the creation of one object, with the text set to ‘Hello There’ as this is the value of the property prior to the
build()method being called.The example below demonstrates this.