DEV Community

Discussion on: Builder Design Pattern

 
thomaswdmelville profile image
Thomas Melville

I agree, the internals of the class (i.e. non final fields) would determine if it's thread safe or not.

I agree, in the case where the builder is static is not thread safe. Why shouldn't it be shared between threads though? My understanding of this pattern is that it's about object creation, in a way that makes the code more maintainable and reduces the chances of objects with incorrect state. I haven't seen any mention of concurrecny.

I've put 3 possible builder implementations in my pattern-play repo, as you may have guessed I use it for learning patterns
github.com/ethomev/pattern-play/tr...

I like the pattern where there is only one constructor for the object and it takes the builder. I think I will use this implementation the next time I need to use the builder pattern.

P.S. Sorry for the delay in replying, I'm now a father of 2 so I have less free time ;-)