Sunday, November 26, 2017

Nice Java Builder pattern example

Have to say I mostly use just the bean style setters and getters in the past, but came across this blog online:
https://jlordiales.me/2012/12/13/the-builder-pattern-in-practice/
It's really a neat explanation. I think in the future when we want to build immutable objects with optional fields, we should definitely use the builder pattern instead. I especially like the invariant checking part where the check is on the object fields rather than the builder fields, and make it thread safe.

0 Comments:

Post a Comment

<< Home