the instance of the builder is passed to Builder.build(this) method
That sounds like you are passing an instance of Builder
to a static method of Builder
, which seems very unlikely.
I can think of two answers to your question. My favorite is that objects that never change are easier to use and safer than objects that change. If your program ever has problems, finding those problems will always be made harder by each object that may be changing over its lifetime, especially if multiple threads are involved. Even better than an object that never changes is an object that cannot change because it has methods that could cause it to change if called.
Another answer to your question is that even when an object is allowed to change over time, there are often constraints about what states are legal. You'll probably run into this in practice, but realistic examples are difficult to construct artificially. An unrealistic example would be a class ShapePosition
that contains a Point
and a Shape
, and requires that the Point
always be inside the Shape
. It would be impossible to construct a ShapePosition
by using a no-arguments constructor followed by setPoint
, and setShape
without causing the ShapePosition
to exist briefly in an illegal state, and that means you won't be able to enforce that every ShapePosition
must always be legal. Using a builder, you can completely avoid that issue by allowing the builder to be in states that wouldn't be legal for the final …