I read "effective java" where it is suggested to use the builder pattern when classes have several optional build arguments. A rational being has advantages over -
A "telescopic pattern" that basically provides one constructor with a require pattern, another with a required + 1 optional, another with a "required + 2 optional", etc. - the author shares that it becomes too difficult to read and write when optional parameters get out of control
'A Javabeans template - which uses a constructor with no arguments, and then runs the installer for each parameter - the drawback here is thread safety - because the object goes through several methods - and may be available when building, which causes unexpected behavior in parts far from the code
Recommended builder template - uses the "static" internal member of the class in the class with optional arguments - clients build the "builder" in the "java beans" style construct, and then call the class constructor, which mainly uses the builder members to set their fields
Phew!
My question is, given that the builder is a static member, could other threads in the application also access and potentially change the attributes of the builders at the same time? Cause unexpected behavior?
No thread programming experience, please forgive me if this is a stupid question
source
share