Java Builder Pattern Explained in 3 Minutes

preview_player
Показать описание
Java Builder Pattern Explained

The builder pattern in Java is a powerful way to construct objects with many 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 in Java with advanced validation, including an advanced builder with a fluent api created with interface chaining.

00:00 What is a builder in Java?
00:37 Java beans
00:56 Simple Java builder
01:19 Java builder with validation
01:33 Java builder with required fields
02:13 The dark arts
Рекомендации по теме
Комментарии
Автор

What topic would you be interested in learning about next?

jack.hodkinson
Автор

I love this no-fluff approach. Simple and straight to the point. Sub +1

Play_Streams
Автор

Thanks for the video. Explained very well compared to some of the other tutorials I've seen online.

jamessinnott
Автор

Wow, very impressive explanation and coding style. The channel I was looking for but didn't know existed. Thank you very much!

DominikusHerzberg
Автор

Nice. I normally prefer to use runtime checks and exceptions, but for more complex objects the multiple interfaces may pay up?

Here's an idea for a followup video: You have three classes: an abstract Base class and classes A and B which extend it. Create builders for them without code duplication.

IvanToshkov
Автор

I like your explanations so much! Always on point and really helpful, great job 👍

returncode
Автор

also lombok @Builder makes the job easier, thanks good video

DamLee
Автор

Nice explanation, can't wait for more

vendettavera
Автор

Can you pls create complete playlist for along with real time project in Java 8 for collage student

mrindian
Автор

Would this be needed if Java had named parameters?

noelgomile
Автор

Could you share the editor theme from the examples?

ИвелинъСтояновъ
Автор

You can use also a Record class, the fields in a record class are immutable as well.

SeamanGR
Автор

Coding setters as chain-able methods is always satisfying:

instead of- void setX () { … }
using- ClassName setX() { … return this; }

so you can theoretically:
object.setX( v1 ).setY( v2 )…

The only issue is if the setter’s aren’t final (returning a value other than this)— setters should probably be final anyhow (unless you have some sort of EventDispatch system).

tylerbakeman
Автор

Thanks for the explanation. I feel like this is only needed because of modern features that other languages have and Java doesn't.
I had some experience with Dart and I loved its named constructors and named mandatory and optional parameters. I will never understand why this doesn't get added to Java

bcampera
Автор

Love it and subscribed after watching fist 15 seconds of this video.❤

prodevops
Автор

Thanks a lot for this video! +1 sub, so don't stop recording the interesting videos :)

maximschott
Автор

Java seriously needs to consider adding support for named parameters. There is just too much one needs to to in order to have the same functionality as python, dart and kotlin named parameters (it would also help a lot with deconstruction patterns, which they are trying to get good using the new proposed "with" keyword

Ewig_Luftenglanz
Автор

WOW, explained more in 3 min than some books...

sobeck
Автор

It is so mind boggling that you have imbibed so much into a 3 minute video!

softwaretactics
Автор

why just return class object in setter? so alots of codes are removed and result is the same.

farshidnaqizadeh