Java Clean Code Tutorial #3 - Builder Design Pattern Example

preview_player
Показать описание
Episode 3 of the free Java Clean Code Training Series.

So what is the builder pattern and why is it needed?
The Gang of Four Builder pattern is an object creation software design pattern.

It solves many problems and challenges such as the never-ending constructor parameter anti-pattern.

Benefits of the java builder pattern:
- No need to pass Null objects into the constructor.
- You don’t need to guess or try to work out which constructor parameter maps to a certain object’s field. Error prone!
- Easily made into an Immutable class. You can now share the object safely between threads or in a multi-threaded environment as you don’t need to worry about mutation of variable state.
- Provides control over object construction steps and provides meaningful semantic method names.
- Increases the use-ability, maintainability and readability of code when creating objects.

Software is written once and read hundreds of times. So let’s make our fellow developers life easier.

Why clean code?
Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers.

Don’t forget to subscribe for your regular dose of Java Tutorials!
STOP THE ROT.

Till episode 4,

Philip
Рекомендации по теме
Комментарии
Автор

I've been learning software development - in Java specifically - for the last couple of months now (having decided on a career change a little while back). Like a lot of things in programming right now, design patterns are pretty new to me; but in spite of that I found this tutorial valuable, so thanks for explaining so clearly. Will be sure to check out your other videos!

EsotericDog
Автор

Hi! I'm a brazilian guy, and my professor of Object-Oriented ask me to present to the class this design pattern that you teach very well, it helps me a lot! Thank you so much!

jpfsilva
Автор

Great example all things explained practically and nice explanation thanks

rajatagrawal
Автор

Thanks for explaining the context of the design pattern, lot of other videos I watched skipped over it and it becomes hard to follow.

Mohammed-hwkz
Автор

what a nice example in a short video...thanks man

rabiunislam
Автор

thanks for explaining the builder design pattern.

uma_mataji
Автор

Thanks...I agree with @Ravi Pradhan...good tutorial...

davindersingh-evlu
Автор

Great explanation, Philip! I tried to grasp from a website then Derek Banas's video here - he constructed this pattern bit differently than what I studied on a website
it was bit difficult to understand WHY behind the pattern after glancing at the website
but the explanation you put here helped to understand WHY :) so thank you a ton!!!

dhruva
Автор

Curious, how could we achieve the same thing, but without duplicating fields? Is it even a problem having duplicated fields?

mnbvcxz
Автор

hei man, great lesson, you actually made me. understand this design patterns. Could we see in the future more videos about design patterns?

Lunarspear
Автор

Thanks for making this wonderful video. After watching it, I tried to use it in my code. Suppose I have 3 methods and in these 3 methods I am getting details from user about processor, ram, colour so how we have to save this information. Are we creating a builder to store the values or we have to create local variables and after storing values in these variables we need to store into our Builder(In this case only one builder will be created because we are storing values into variables first but in this case we need to create so many variables). In second approach, if we are storing each value in different builder then we need to create multiple builders. So which approach is better as according to you?

manindersingh
Автор

1. What is guava? what it is used for?
2. what is the best way of making a class immutable?
can you make a tutorial on these?
thank you

StefanBanu
Автор

Thanks for the video.
Is there a way to enforce (by the compiler) that all parameters are actually set? I've read that you can set required parameters in the constructor of the builder and the optional ones in setters of the builder as shown in your video. This works well if only one parameter is required and the rest optional. But what if all parameters must not be null and there are no default values?

KimKernGplus
Автор

What if I have a field or two that CAN be muttable. Imagine a Person class which has a rank as a field and it might be changed over time .
Can I just remove the final keyword? Or is it necessary for all the fields to be final?

arfsufpe
Автор

Thanks for this sharing this but video quality is really poor. If you could enhance the pixels would be a great help !!

DamanDhillon
Автор

You just multiplied your code base by about 4 times.

bikeaday
Автор

Please, please, please, never do that! It's just plain stupid and has nothing to deal with the original Gang of Four builder pattern! It multiplies boilerplate code enormously and adds no real value. Plus down the road when somebody needs to change those final values, it will be a huge PIA...

nickgoupinets
visit shbcf.ru