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.
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.
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.
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.
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.
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
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 😜
@@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.
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)
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~
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?
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)…
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)?
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.
@@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.
@@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.
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?
@@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.
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
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.
thanks for information.
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.
Wish you all the best with your interview!
how was the interview?
Discovered your channel today, great series of videos, deserves more views!
Thanks! I really appreciate it. I have more videos planned for this series as well.
Your channel is underrated. (full stop!)
There are very few good teachers and you are one of them. Amazingly explained. Loved it. And thanks for that.
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.
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.
so clean. Your videos are perfect little nuggets for beginners. Enough info to understand the "why" without getting bogged down in the weeds. Thanks!
You are very welcome!
I like short videos that only explain one thing vs long tut videos that do it all.
Thanks for the clear and straightforward explanation of this concept! The examples you used helped me understand builders a lot better.
Beautiful article. Well explained, loved it. Thank you.
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.
Great stuff buddy! Love these pattern explinations.
Great Explanation with examples! Keep it up, man!
Great stuff Kyle ! Loved these design patterns, keep up the good work :)
This is very useful. Perfect req fields
Imagine having builder class for every class taking care of super classes and child classes and composition
Thank you very much!!!
Thanks for sharing !
Thanks. Trying to learn Builder Pattern in Java, and found your video very helpful 🙂
Simple, useful and very clear. Thanks man for that amazing content!
This is so slick. Very nice.
Good explanation!
The first one is builder pattern. Second example is called "named parameters" , you can use it in classes and functions.
whats the idea behind creating new class called UserBuilder , we can simply add all set methods inside the class user itself ?
Hi, why we've used build method in builder class ? Like what's wrong about using builder class.
where did you get that boomerang in the background?
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.
Thanks. Pretty nice explanation, subscribed
Thank you so much, well explained and all
Thank you. Can you please tell how did you linked live server to javascript
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
Really helpful. I was looking for python examples but the ones I found were making it bit too complicated, this was simple and precise.
Why not use "Object.assign(this, options)". It prevents use to write this.address = address etc
how would we implement this? Like this(?):
class User {
constructor( name,{age,phone,address}={} ) {
User.assign(this, name, age, phone, address)
}
}
Why don't you use const instead of let, when initiating class?
Let allows to update field within the scope while CONST don't.
Great video !!! Thanks for sharing this knowledge !
You're welcome!
Shouldn't you use extends?
good video, please keep up and do more videos. thanks
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 😜
@@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.
Kyle, how about using optional parameters like constructor(name?, age?) ?
By default every parameter in javascript is optional.
@@WebDevSimplified thanks for replying boss
is there a video on Factory Design Pattern ?
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)
Hey, can you say Backbone's way of initializing views and models, uses the second approach of the builder design pattern?
Thanks !
Very good stuff
Keep up the good work man!! Your channel is going to be epic one day 👍🏻👍🏻👍🏻
Thanks!
Exactly!
And now today he has 1M subs
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~
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?
for the second methode is that available just in javaScript ? and why not for other languages ?
can we use this design pattern with react js?
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.
Correct... Heres an example on java ruclips.net/video/0GTe8e7DYHk/видео.html
Thank you :) Need more pattern please
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)…
Can we do this with keyword arguments like **kwargs in python
Why don't we just put a setter and getter inside the User class?
It's pretty time consuming to write for every single property.
AND
I personally don't like that interface...
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
Kyle, can you do a design pattern series? :)
What's the advantage of using a builder comparing to using setters directly in the user class? Sorry I didn't quite get it
Interesting, thanks for this, but quick question - why no semi-colons? Are they not needed anymore in javascript?
They are not needed anymore.
thanks a lot
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)?
Thank you for Video Kyle. I actually have a doubt if we can call any parameters for multiple times in the builder pattern?
Great video, I wonder if there is a way to implement builder like in JS with php, regardless the original way
What do you mean? You can implement this pattern in any programming language of your choice.
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.
makes me really appreciate python kwargs
Which theme is this in your VB Code
I love it, plz name it.
It is just the default dark theme.
That was funny lol
Really useful video!
But resolution options are available in the only 360p.
I am able to select 1080p resolution on this video. Maybe youtube was having some trouble when you tried to view the video.
@@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.
Where is the director. I am confused. I have seen other tutorials where they use something called a director.
Can't you just remove 'age' and 'phone' from the constructor, and put the Setters in the User class?
Exactly what I was thinking.
agree, quite misleading....
@Sagy Assor the reason is explained at the beginning of the video
@@m3awna in what exact time?
@@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.
Why can't we simply use named parameters?
So this is like the state Hook in React?
You are a Legend.
nice
your doing so good man
Thanks!
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?
Maybe I'm old school but I like the having semicolons. What does everyone else think?
awesome thank you
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? 😂
thx from Russia..!
Why don't we just put the setters method inside the user class with constructor having one parameter "name"
thank you
when I use the build method it returns an undefined even though I did exactly as you did !!!
Thanks
You're welcome!
cool...👍
Thanks!
//why not just do this:
class User{}
var user=new User();
user.name="asd";
user.address=new Address("1","main");
Bro you make coding simplified !!
Thanks! That is the goal.
thank you so muchh
builder pattern is confusing w/ all those "this' keywords.
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.
Please do a hair styling tutorial.
Its painful when you write code without semicolon 😨
Semicolons aren't needed and only make the code messy in my opinion.
@@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.
Please tell me you work at google? You are damn good. Thanks for explaining this.
Why can't a C++ Builder Pattern be this simple? haha
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
POV: how to get a 500 words line in js
You should really use console.table() for these examples :)