Builder Pattern - Design Patterns

  Рет қаралды 133,727

Web Dev Simplified

Web Dev Simplified

Күн бұрын

As a programmer creating objects is one of the most common things that you will do. It is so common that many of us never think twice about how we do it, but this can lead to incredibly messy code. This is where the builder pattern comes in. The builder pattern is one of the best creational design patterns for creating complex objects without complicating your constructors or code. The best part about the builder pattern is that the new changes to JavaScript allow us to create extremely concise builders compared to the traditional way of creating builders.
Design Pattern Playlist:
bit.ly/2QrGnDq
Design Pattern Repository:
github.com/WebDevSimplified/D...
Twitter:
/ devsimplified
GitHub:
github.com/WebDevSimplified
CodePen:
codepen.io/WebDevSimplified
#BuilderPattern #DesignPatterns #Programming

Пікірлер: 128
@DodaGarcia
@DodaGarcia 6 ай бұрын
The purpose of the Builder pattern is not just so that you can have optional parameters, it's to separate the construction of an object from its representation. Of course it's overkill if all your setters are going to be this.property = value, but it should be communicated that there's a massive benefit in using the pattern for cases where properties need to be validated before being set, or where setting them affects properties that had been set beforehand and so on.
@KamelJabber1
@KamelJabber1 5 жыл бұрын
Discovered your channel today, great series of videos, deserves more views!
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thanks! I really appreciate it. I have more videos planned for this series as well.
@jordanski5421
@jordanski5421 3 жыл бұрын
I was so stuck trying to implement this functionality in my application but know I know this pattern it's made things incredibly easy, thanks for sharing.
@jonathanmartinez7912
@jonathanmartinez7912 4 жыл бұрын
Thanks for the clear and straightforward explanation of this concept! The examples you used helped me understand builders a lot better.
@Solarium501
@Solarium501 Жыл бұрын
I am preparing for a technical test for applying to a company and during the interview they hinted out that the test is going to be mostly about design patters. I have never heard of design patterns before and every source on the internet is confusing. However, you are just making it simple and understandable by breaking down each pattern. Thank you so much for these videos. Subscribed.
@jetbob309
@jetbob309 Жыл бұрын
Wish you all the best with your interview!
@matis9783
@matis9783 25 күн бұрын
how was the interview?
@brijspy
@brijspy 3 жыл бұрын
Great stuff Kyle ! Loved these design patterns, keep up the good work :)
@tubehelpr
@tubehelpr 4 жыл бұрын
Great stuff buddy! Love these pattern explinations.
@austinlords
@austinlords 4 жыл бұрын
so clean. Your videos are perfect little nuggets for beginners. Enough info to understand the "why" without getting bogged down in the weeds. Thanks!
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
You are very welcome!
@VibhavChaddha
@VibhavChaddha 3 жыл бұрын
There are very few good teachers and you are one of them. Amazingly explained. Loved it. And thanks for that.
@KyleRebstock
@KyleRebstock 2 жыл бұрын
This is good stuff. Glad someone did a good JS vid on this pattern. I think it would be nice to show more of the most powerful reason why you use the builder method which you did allude to at the very end. When an object ends up having to pass many objects to the constructor that could just be composed and built out with builder methods. That's where the real power shows up. Love your content. Great presentation. Would love to see more.
@davesomeone4059
@davesomeone4059 Жыл бұрын
I like short videos that only explain one thing vs long tut videos that do it all.
@unique_god
@unique_god 2 жыл бұрын
Imagine having builder class for every class taking care of super classes and child classes and composition
@harshpatel7704
@harshpatel7704 2 жыл бұрын
Your channel is underrated. (full stop!)
@user-tx9gj9cd8f
@user-tx9gj9cd8f 10 ай бұрын
Simple, useful and very clear. Thanks man for that amazing content!
@cesarmuzio1154
@cesarmuzio1154 2 жыл бұрын
Thanks for sharing !
@deependrajoshi199
@deependrajoshi199 Жыл бұрын
Beautiful article. Well explained, loved it. Thank you.
@NoahNobody
@NoahNobody 2 жыл бұрын
Another great lesson. I'm a php guy, but this is all the same theory. I think accidently created builder class the other day, but now I know what it was I made.
@user-nt9bo3ub6k
@user-nt9bo3ub6k 5 ай бұрын
Great Explanation with examples! Keep it up, man!
@DreQueary
@DreQueary 3 жыл бұрын
This is so slick. Very nice.
@pubti
@pubti 4 жыл бұрын
Thanks. Pretty nice explanation, subscribed
@barakatosalon
@barakatosalon 4 жыл бұрын
Great video !!! Thanks for sharing this knowledge !
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
You're welcome!
@moonshelter9137
@moonshelter9137 4 жыл бұрын
Thank you so much, well explained and all
@kaicooper9421
@kaicooper9421 2 жыл бұрын
This is very useful. Perfect req fields
@techuchiha6510
@techuchiha6510 5 жыл бұрын
Keep up the good work man!! Your channel is going to be epic one day 👍🏻👍🏻👍🏻
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thanks!
@rolikaseventysix
@rolikaseventysix 5 жыл бұрын
Exactly!
@awekeningbro1207
@awekeningbro1207 Жыл бұрын
And now today he has 1M subs
@helgestegemoen73
@helgestegemoen73 Жыл бұрын
Thanks. Trying to learn Builder Pattern in Java, and found your video very helpful 🙂
@yinonelbaz5309
@yinonelbaz5309 Жыл бұрын
Thank you very much!!!
@luisrueda4476
@luisrueda4476 2 жыл бұрын
Good explanation!
@fiddler-dv4or
@fiddler-dv4or 4 жыл бұрын
Thanks for the great break down in this pattern! I love that your doing design patterns for JavaScript. Have you given it any thought on do this series using proto_types?
@GenerikV
@GenerikV 2 жыл бұрын
Really helpful. I was looking for python examples but the ones I found were making it bit too complicated, this was simple and precise.
@joeb.1163
@joeb.1163 3 жыл бұрын
Very good stuff
@yaolegoleynik
@yaolegoleynik 4 жыл бұрын
Thank you :) Need more pattern please
@andersonlavor
@andersonlavor Жыл бұрын
The first one is builder pattern. Second example is called "named parameters" , you can use it in classes and functions.
@quanghong3922
@quanghong3922 4 жыл бұрын
awesome thank you
@amjadshadid90
@amjadshadid90 2 жыл бұрын
thanks a lot
@mdsajaldeowan1054
@mdsajaldeowan1054 3 жыл бұрын
thanks, Kyle for the great video Kyle is it possible to remove the final build method and gets the same result if so then how
@WhiteSiroi
@WhiteSiroi Жыл бұрын
thank you
@yaseralamoodi8314
@yaseralamoodi8314 5 жыл бұрын
good video, please keep up and do more videos. thanks
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thank you. I have a backlog of video ideas so long I fear I will never reach the end of it, so you won't have to worry about me stopping anytime soon 😜
@winter_light
@winter_light 3 жыл бұрын
@@WebDevSimplified could you also do videos on SOLID principles. I find some of them really difficult to grasp. I purchased a course on Udemy but I always end up watching your videos to really understand how these work.
@dudeimadolphin4318
@dudeimadolphin4318 5 жыл бұрын
nice your doing so good man
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thanks!
@sankethb.k642
@sankethb.k642 3 жыл бұрын
Thank you. Can you please tell how did you linked live server to javascript
@cleverengineer2410
@cleverengineer2410 Жыл бұрын
You are a Legend.
@maliksalman6504
@maliksalman6504 Жыл бұрын
Thank you for Video Kyle. I actually have a doubt if we can call any parameters for multiple times in the builder pattern?
@praveengundla1235
@praveengundla1235 3 жыл бұрын
Thanks a lot for your effort.. BTW in builder class methods we are setting properties of actual user object , i.e. in setphone method setting phone property of user object so user is not immutable ... So why can't we set these properties individually from the client (calling code)?
@kinansharif5625
@kinansharif5625 2 жыл бұрын
Hey, can you say Backbone's way of initializing views and models, uses the second approach of the builder design pattern? Thanks !
@natqe4049
@natqe4049 5 жыл бұрын
Thanks
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
You're welcome!
@emirsalihovic6616
@emirsalihovic6616 2 жыл бұрын
Kyle, can you do a design pattern series? :)
@fabioribeirodecarvalho2382
@fabioribeirodecarvalho2382 3 жыл бұрын
I'm wondering if use the get and set method could be a way to solve this problem....thanks for the course, it help us a lot...ok I tested this way, but I realize we cannot declare a property class like private to try esolation them. So, the method getters and setters become useless in this case...I reviewed the case and we can has the private fields with # before the variable name
@zerobit778
@zerobit778 Жыл бұрын
One thing that the Builder could be better than named Parameters is that : When the set.... method not only need set the value solely but has other logics which may relate to other parts. Please verify my guess. Thanks~
@shivammakwan6409
@shivammakwan6409 5 жыл бұрын
cool...👍
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thanks!
@idev6775
@idev6775 3 жыл бұрын
thank you so muchh
@soniablanche5672
@soniablanche5672 4 жыл бұрын
Wouldn't it make more sense to create the User object inside the build method? That way you can build as many different User object as you want.
@JPTechForum
@JPTechForum 4 жыл бұрын
Correct... Heres an example on java kzbin.info/www/bejne/Zni3lmubbKmMfs0
@usmaness
@usmaness 4 жыл бұрын
Great video, I wonder if there is a way to implement builder like in JS with php, regardless the original way
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
What do you mean? You can implement this pattern in any programming language of your choice.
@purduetom90
@purduetom90 3 жыл бұрын
Yes, you can do the first way in PHP. Methods in a php class can return $this. Works beautifully and is a great way to eliminate the use of long parameter lists.
@TheHuntingSpot
@TheHuntingSpot 2 жыл бұрын
Maybe I'm old school but I like the having semicolons. What does everyone else think?
@harag9
@harag9 4 жыл бұрын
Interesting, thanks for this, but quick question - why no semi-colons? Are they not needed anymore in javascript?
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
They are not needed anymore.
@3ab9ari1
@3ab9ari1 4 жыл бұрын
for the second methode is that available just in javaScript ? and why not for other languages ?
@konstantinkkk8397
@konstantinkkk8397 3 жыл бұрын
Hi, I cannot find optional parameters on MDN or any other resourses. It looks like destructuring and thats all. No need to call it optional parameters? or I mistake?
@abdelrhmanshokr7546
@abdelrhmanshokr7546 4 жыл бұрын
when I use the build method it returns an undefined even though I did exactly as you did !!!
@mahdisalem3776
@mahdisalem3776 Жыл бұрын
whats the idea behind creating new class called UserBuilder , we can simply add all set methods inside the class user itself ?
@FluidEnjoyer
@FluidEnjoyer 2 жыл бұрын
Can't you create the "functions" from the first builder in the user class itself? I don't see to point of the builder object.
@Luxcium
@Luxcium 2 жыл бұрын
I tend to keep separate objects with data value from objects with methods and properties (getters and/or setters)… what wording (or naming) could be used to describe such objects in JavaScript? I would tend to use POJO but it’s not like it is something that is without any method or I would call it a JSON like object (obviously it wouldn’t have a constructor)…
@davidjustice2323
@davidjustice2323 4 жыл бұрын
Kyle, how about using optional parameters like constructor(name?, age?) ?
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
By default every parameter in javascript is optional.
@davidjustice2323
@davidjustice2323 4 жыл бұрын
@@WebDevSimplified thanks for replying boss
@ivanpavlovnorth
@ivanpavlovnorth 4 жыл бұрын
Really useful video! But resolution options are available in the only 360p.
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
I am able to select 1080p resolution on this video. Maybe youtube was having some trouble when you tried to view the video.
@ivanpavlovnorth
@ivanpavlovnorth 4 жыл бұрын
​@@WebDevSimplified I familiar with that thing, but it was so strange to watch it twice on 360p on two different devices... As it turns out the problem is in Firefox on Windows 10 N. Thanks for smooth picture at 60fps.
@TheHuntingSpot
@TheHuntingSpot 2 жыл бұрын
where did you get that boomerang in the background?
@Klinoklaz
@Klinoklaz Жыл бұрын
What's the advantage of using a builder comparing to using setters directly in the user class? Sorry I didn't quite get it
@maheerali531
@maheerali531 4 жыл бұрын
Why not use "Object.assign(this, options)". It prevents use to write this.address = address etc
@eldwinc9884
@eldwinc9884 4 жыл бұрын
how would we implement this? Like this(?): class User { constructor( name,{age,phone,address}={} ) { User.assign(this, name, age, phone, address) } }
@Q99a
@Q99a Жыл бұрын
Hi, why we've used build method in builder class ? Like what's wrong about using builder class.
@elhamuddin.mahmoodi
@elhamuddin.mahmoodi 4 жыл бұрын
Which theme is this in your VB Code I love it, plz name it.
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
It is just the default dark theme.
@davidfonseca698
@davidfonseca698 4 жыл бұрын
That was funny lol
@deansprivatearchive
@deansprivatearchive 3 жыл бұрын
Shouldn't you use extends?
@technomaestro6092
@technomaestro6092 2 жыл бұрын
Can we do this with keyword arguments like **kwargs in python
@aryankumar87771
@aryankumar87771 Жыл бұрын
is there a video on Factory Design Pattern ?
@skalippanbalippan6972
@skalippanbalippan6972 4 жыл бұрын
Why don't we just put a setter and getter inside the User class?
@blank-vw2sb
@blank-vw2sb 3 жыл бұрын
It's pretty time consuming to write for every single property. AND I personally don't like that interface...
@jamshediqbal7936
@jamshediqbal7936 4 жыл бұрын
Why don't you use const instead of let, when initiating class?
@starman9000
@starman9000 4 жыл бұрын
Let allows to update field within the scope while CONST don't.
@shivabansfore7510
@shivabansfore7510 Жыл бұрын
can we use this design pattern with react js?
@imadetheuniverse4fun
@imadetheuniverse4fun Жыл бұрын
makes me really appreciate python kwargs
@blackpurple9163
@blackpurple9163 Жыл бұрын
So this is like the state Hook in React?
@rnater7145
@rnater7145 2 жыл бұрын
I'm surely not understanding something. Why even use a builder class in the first approach? afaik this is valid code (assuming that each set method returns _this_): const user = new User('Bob').setAge(22).setPhone(phone)
@r3boxx
@r3boxx 6 ай бұрын
Where is the director. I am confused. I have seen other tutorials where they use something called a director.
@d0paminer
@d0paminer 2 жыл бұрын
thx from Russia..!
@jarwishroshan4298
@jarwishroshan4298 2 жыл бұрын
Hey you're posting Great Stuff man!! Thank you for that. Btw Can you show us how do you run your js files in browser? 😂
@donnytechiera957
@donnytechiera957 4 жыл бұрын
Bro you make coding simplified !!
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
Thanks! That is the goal.
@JimmyC0
@JimmyC0 2 жыл бұрын
Why don't we just put the setters method inside the user class with constructor having one parameter "name"
@sagyas
@sagyas 3 жыл бұрын
Can't you just remove 'age' and 'phone' from the constructor, and put the Setters in the User class?
@baphnie
@baphnie 3 жыл бұрын
Exactly what I was thinking.
@arkilisx
@arkilisx 2 жыл бұрын
agree, quite misleading....
@faridguelmi7123
@faridguelmi7123 2 жыл бұрын
@Sagy Assor the reason is explained at the beginning of the video
@sagyas
@sagyas 2 жыл бұрын
@@faridguelmi7123 in what exact time?
@matikb.6733
@matikb.6733 2 жыл бұрын
@@sagyas I agree, and believe this at 1:50 is the reason, Building is nice. Also Setters aren't better, cause the Builder implies semanticaly that We are *creating* something - the Setters on the other hand just say that You *set* something... "But on what purpose", coz the constructor is right there? - Code Viewers could ask. Plus You can feel like Java Dev with Builders - I don't believe that it's a negative name.
@adityamishra348
@adityamishra348 2 жыл бұрын
Why can't we simply use named parameters?
@Vibestr
@Vibestr 3 жыл бұрын
builder pattern is confusing w/ all those "this' keywords.
@fredianriko5648
@fredianriko5648 3 жыл бұрын
not really if you understand the meaning of "this" keyword first, try to understand it and make resume of what you understand with your own word.
@Ali-mc4le
@Ali-mc4le 3 жыл бұрын
Please tell me you work at google? You are damn good. Thanks for explaining this.
@NitinKatiyarCircle
@NitinKatiyarCircle 4 жыл бұрын
Its painful when you write code without semicolon 😨
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
Semicolons aren't needed and only make the code messy in my opinion.
@NitinKatiyarCircle
@NitinKatiyarCircle 4 жыл бұрын
@@WebDevSimplified I find them make code more clear. When changing syntax in multiple line then it make it clear where it ends. Visual studio 2017 also show an error when do not use semicolon. Also it brings c# and other serverside languages closer to js. Well it's just me. Everyone has their preferences.
@xBZZZZyt
@xBZZZZyt 3 жыл бұрын
//why not just do this: class User{} var user=new User(); user.name="asd"; user.address=new Address("1","main");
@mattmaloney5988
@mattmaloney5988 3 жыл бұрын
Please do a hair styling tutorial.
@olegsuprun7590
@olegsuprun7590 3 жыл бұрын
Im sorry but this is not a classic builder pattern, you also have to implement a director class, and pass a builder object to it , then call construct() on the director and get product from builder
@guitarboy12
@guitarboy12 3 жыл бұрын
Why can't a C++ Builder Pattern be this simple? haha
@largo17
@largo17 2 жыл бұрын
You should really use console.table() for these examples :)
Singleton Pattern - Design Patterns
8:28
Web Dev Simplified
Рет қаралды 150 М.
Builder Design Pattern Explained in 10 Minutes
10:45
Kantan Coding
Рет қаралды 22 М.
Miracle Doctor Saves Blind Girl ❤️
00:59
Alan Chikin Chow
Рет қаралды 57 МЛН
Black Magic 🪄 by Petkit Pura Max #cat #cats
00:38
Sonyakisa8 TT
Рет қаралды 36 МЛН
ATM Interface Using Python
3:51
Code Rocks
Рет қаралды 6
Command Pattern - Design Patterns
14:49
Web Dev Simplified
Рет қаралды 96 М.
10 Design Patterns Explained in 10 Minutes
11:04
Fireship
Рет қаралды 2,1 МЛН
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 176 М.
Strategy Pattern - Design Patterns (ep 1)
35:11
Christopher Okhravi
Рет қаралды 1,4 МЛН
JavaScript Design Patterns #10 - Builder Pattern
11:26
DevSage
Рет қаралды 11 М.
Composition Vs Inheritance - Why You Should Stop Using Inheritance
10:16
Web Dev Simplified
Рет қаралды 171 М.
Why Is Array/Object Destructuring So Useful And How To Use It
13:24
Web Dev Simplified
Рет қаралды 418 М.
Miracle Doctor Saves Blind Girl ❤️
00:59
Alan Chikin Chow
Рет қаралды 57 МЛН