Тёмный

Java Builder Pattern Explained in 3 Minutes 

Jack Hodkinson
Подписаться 2,2 тыс.
Просмотров 12 тыс.
50% 1

Java Builder Pattern Explained in 3 Minutes
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.
Support me on Patreon: / jackhodkinson
Source code: github.com/jrhodkinson/youtub...
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

Опубликовано:

 

8 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 40   
@Jack_Hodkinson
@Jack_Hodkinson 2 месяца назад
What topic would you be interested in learning about next?
@PilarczykM
@PilarczykM Месяц назад
Any design pattern will be valuable 🤗
@Play_Streams
@Play_Streams 2 месяца назад
I love this no-fluff approach. Simple and straight to the point. Sub +1
@Jack_Hodkinson
@Jack_Hodkinson 2 месяца назад
Thank you!
@DamLee88
@DamLee88 2 месяца назад
also lombok @Builder makes the job easier, thanks good video
@IvanToshkov
@IvanToshkov 3 месяца назад
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.
@DominikusHerzberg
@DominikusHerzberg 3 месяца назад
Wow, very impressive explanation and coding style. The channel I was looking for but didn't know existed. Thank you very much!
@returncode0000
@returncode0000 4 месяца назад
I like your explanations so much! Always on point and really helpful, great job 👍
@Jack_Hodkinson
@Jack_Hodkinson 4 месяца назад
Thank you :)
@PilarczykM
@PilarczykM Месяц назад
Very good explanation 🎉
@vendettavera4641
@vendettavera4641 Месяц назад
Nice explanation, can't wait for more
@burningfire2k
@burningfire2k 3 месяца назад
That was a fast explanation 👏
@bcampera
@bcampera 14 дней назад
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
@mrindian7422
@mrindian7422 4 месяца назад
Love the way you think ❤
@prodevops6271
@prodevops6271 3 месяца назад
Love it and subscribed after watching fist 15 seconds of this video.❤
@vasealis
@vasealis 2 месяца назад
You can use also a Record class, the fields in a record class are immutable as well.
@loyyeeko1231
@loyyeeko1231 3 месяца назад
wonderful
@davidgrajalesmirage
@davidgrajalesmirage 2 месяца назад
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
@user-lj6xj5bg6o
@user-lj6xj5bg6o 3 месяца назад
I am your 1000th number Subscriber
@Jack_Hodkinson
@Jack_Hodkinson 3 месяца назад
Thank you! Welcome
@tylerbakeman
@tylerbakeman 3 месяца назад
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).
@ShubhamKumar-vh7ti
@ShubhamKumar-vh7ti 3 месяца назад
Subscribed
@Jack_Hodkinson
@Jack_Hodkinson 3 месяца назад
Thank you!
@mrindian7422
@mrindian7422 4 месяца назад
Can you pls create complete playlist for along with real time project in Java 8 for collage student
@Jack_Hodkinson
@Jack_Hodkinson 4 месяца назад
Working on it! I have a live coding project here, where I implement an ArrayList in real time ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-P2P-ZUvIsZM.html
@mrindian7422
@mrindian7422 4 месяца назад
@@Jack_Hodkinson Thank you very much
@user-xb4dj3ky6m
@user-xb4dj3ky6m 2 месяца назад
Could you share the editor theme from the examples?
@Jack_Hodkinson
@Jack_Hodkinson 2 месяца назад
Hi, the examples are all written in markdown using Marp (marp.app/). I use the Visual Studio Code extension.
@sobeck6900
@sobeck6900 2 месяца назад
WOW, explained more in 3 min than some books...
@noelgomile3675
@noelgomile3675 2 месяца назад
Would this be needed if Java had named parameters?
@Jack_Hodkinson
@Jack_Hodkinson 2 месяца назад
Good question. Not really!
@dentjoener
@dentjoener 2 месяца назад
I always tell people that builders are just shitty excuses for named parameters. I tend to shy away from them because I hate them with a passion. Use smaller objects that can be composed into larger objects, link this with some domain driven design (a name might be a string, but an Email sure as hell shouldn't be), and there's way less issues. Also static factory methods >>> constructors.
@softwaretactics1536
@softwaretactics1536 2 месяца назад
It is so mind boggling that you have imbibed so much into a 3 minute video!
@poloolo69
@poloolo69 3 месяца назад
real
@farshidnaqizadeh159
@farshidnaqizadeh159 3 месяца назад
why just return class object in setter? so alots of codes are removed and result is the same.
@desoroxxx
@desoroxxx 3 месяца назад
No, otherwise you wouldn't be able to chain them
@scarletdice
@scarletdice 2 месяца назад
then you have a class that is mutable. might not what you want when immutability is intended.
@terrytorres5026
@terrytorres5026 2 месяца назад
Wholy crap,then we wonder why coding is overcomplicated and breaks when new releases of Java come out.
@josepescina4360
@josepescina4360 2 месяца назад
too much work
Далее
Java Interface Tutorial - Easier than You Think!
12:49
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Clean Coding: Das verstehen alle falsch!
12:11
Просмотров 11 тыс.
Builder Design Pattern (with Java Implementation)
8:44
Java Generics Explained
13:45
Просмотров 45 тыс.
8 Design Patterns | Prime Reacts
22:10
Просмотров 382 тыс.
Шаблоны Java. Builder (Строитель)
10:58