Josh Bloch's Builder Pattern as a Lombok annotation?

340 views
Skip to first unread message

Brian R. Jackson

unread,
Jan 31, 2011, 1:21:40 PM1/31/11
to Project Lombok
I see there is a thread from 2009 that seems to broach the subject of
Bloch's Builder pattern but I wanted to bring it up again since its
code I rewrite frequently. Here is a description of the pattern:

http://rwhansen.blogspot.com/2007/07/theres-builder-pattern-that-joshua.html

Here is an interesting library I just found that tries to simplify the
boilerplate code of the pattern:
http://garbagecollected.org/2007/07/12/builder-pattern-deluxe/

Before reading the thread from 2009 I envisioned that choosing this
feature would be a new boolean value on @Data like @Data(buildable =
true)

The thread I'm referring to is here:
http://groups.google.com/group/project-lombok/browse_thread/thread/906972e9053122da/b1f3f71faa03bfed

rjee

unread,
Jan 31, 2011, 4:35:14 PM1/31/11
to Project Lombok
We really like the idea of the builder pattern, though there are a lot
of options. Do we want to support getters on the builders, do we want
support Lists out of the box (supporting an 'add' construction to the
List), do we want the annotation to be on a separate class or do we
put it on the class itself, do we want to support default values....
and the list goes on.

but, like we said it's a good idea but we want the time to finalize a
proposal, and that's not going to happen before we get the 0.10
release out of the door. We'll let you know when we have a better
sense of directions within the jungle that is Builder.

On Jan 31, 7:21 pm, "Brian R. Jackson" <br...@jaxzin.com> wrote:
> I see there is a thread from 2009 that seems to broach the subject of
> Bloch's Builder pattern but I wanted to bring it up again since its
> code I rewrite frequently.  Here is a description of the pattern:
>
> http://rwhansen.blogspot.com/2007/07/theres-builder-pattern-that-josh...
>
> Here is an interesting library I just found that tries to simplify the
> boilerplate code of the pattern:http://garbagecollected.org/2007/07/12/builder-pattern-deluxe/
>
> Before reading the thread from 2009 I envisioned that choosing this
> feature would be a new boolean value on @Data like @Data(buildable =
> true)
>
> The thread I'm referring to is here:http://groups.google.com/group/project-lombok/browse_thread/thread/90...

Brian R. Jackson

unread,
Jan 31, 2011, 4:50:15 PM1/31/11
to Project Lombok
Thanks for the response, I'm glad to hear its not off the radar. Is
there a roadmap or issue tracker available online?

Robbert Jan Grootjans

unread,
Jan 31, 2011, 6:17:24 PM1/31/11
to project...@googlegroups.com
There's an issue tracker on google groups, you can find a link on the
top of the projectlombok.org website... btw, we've already logged
adding a builder annotation quite some time ago, ... it's issue 16 ;)

> --
> You received this message because you are subscribed to the Google
> Groups group for http://projectlombok.org/
>
> To post to this group, send email to project...@googlegroups.com
> To unsubscribe from this group, send email to
> project-lombo...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/project-lombok?hl=en

Brian Jackson

unread,
Jan 31, 2011, 8:09:13 PM1/31/11
to project...@googlegroups.com
Thanks Robbert, that's exactly what I was looking for.

Jared Graber

unread,
Jul 23, 2015, 2:40:53 AM7/23/15
to Project Lombok, br...@jaxzin.com
Bringing this back from the dead :)

I saw that the Builder support was added to the main package with 1.16.0 earlier this year.
I think it would be nice to follow Bloch's pattern a bit more closely though:

When on a class, create a private constructor that takes in the Builder as a parameter. The constructor would then safely copy all the fields from the builder. This is preferable to a constructor with many parameters - at least in my view.
Here's a summary of the pattern:

Obviously the current version does the job, but I think this would be a nice improvement.
Reply all
Reply to author
Forward
0 new messages