#Java Builder Pattern

1 messages · Page 1 of 1 (latest)

storm badge
#

Java Builder Pattern

https://youtu.be/sZYfZrA-gA0

The builder pattern in Java is a powerful way to build objects with many optional fields. A Java builder lets you provide a flexible way to objects without combinations of telescoping constructors.

This video explains why the builder exists, why it's better than java beans, and how to implement a builder with advanced validation, including a spicy builder created with interface chaining.

The builder pattern in Java is a powerful way to build objects with many optional fields. A Java builder lets you provide a flexible way to objects without combinations of telescoping constructors.

This video explains why the builder exists, why it's better than java beans, and how to implement a builder with advanced validation, including a sp...

▶ Play video
ancient marsh
#

Thanks for the share, the "dark art" method is something new I've learned today

#

not sure if i'd ever use the dark art variation tho lol

storm badge
#

I’ve used it quite a bit when creating apis. It’s nice to give people objects to work with that their ide can autocomplete for them without them having to think. It feels great to use. But the implementation is a bit opaque if you’ve never seen it before, so its better when you have this sort of api developer / consumer separation

#

There are some code generation / annotation processing tools that can do this sort of thing too, but I generally prefer implementing them myself to try to avoid too much wizardry

#

But there’s a limit to how complex manually crafted ones can be - the one at the end of the video is probably past the limit realistically. But the first one is simple enough, once you’ve got used to it, and really improves DX

ancient marsh
#

Yeah I can see that being a really good usecase

crimson osprey
#

superb🚀

unkempt valve
#

like that

#

(same as TS i think)