java - When using a Builder Pattern why shouldn't I reuse the builder-object to access the object configuration? -


when using builder pattern why shouldn't reuse builder-object access object configuration? example:

normal way:

objecta(objectbuilder b) {     this.a = b.geta(); } public object geta(){     return this.a; } 

but why can't use this:

objecta(objectbuilder b) {     this.builder = b; } public object geta(){     return this.builder.geta(); } 

thanks :)

a large reason using builder build immutable object: builder mutable, thing builds isn't (necessarily).

if delegate builder, instance mutable again: has reference same instance of objectbuilder can change objecta. means checks on validity of state of objecta @ construction time can invalidated.

if want mutable object, there no need builder: have setters on objecta.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -