Builder Pattern - Design Patterns

Поделиться
HTML-код
  • Опубликовано: 19 дек 2024

Комментарии • 130

  • @DodaGarcia
    @DodaGarcia Год назад +16

    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.

    • @moneylogyy
      @moneylogyy 4 месяца назад

      thanks for information.

  • @Solarium501
    @Solarium501 2 года назад +10

    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 2 года назад +1

      Wish you all the best with your interview!

    • @matis9783
      @matis9783 7 месяцев назад

      how was the interview?

  • @KamelJabber1
    @KamelJabber1 5 лет назад +36

    Discovered your channel today, great series of videos, deserves more views!

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +3

      Thanks! I really appreciate it. I have more videos planned for this series as well.

  • @harshpatel7704
    @harshpatel7704 3 года назад +1

    Your channel is underrated. (full stop!)

  • @VibhavChaddha
    @VibhavChaddha 3 года назад +17

    There are very few good teachers and you are one of them. Amazingly explained. Loved it. And thanks for that.

  • @NoahNobody
    @NoahNobody 3 года назад +1

    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.

  • @jordanski5421
    @jordanski5421 4 года назад +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.

  • @austinlords
    @austinlords 5 лет назад +1

    so clean. Your videos are perfect little nuggets for beginners. Enough info to understand the "why" without getting bogged down in the weeds. Thanks!

  • @davesomeone4059
    @davesomeone4059 2 года назад +1

    I like short videos that only explain one thing vs long tut videos that do it all.

  • @jonathanmartinez7912
    @jonathanmartinez7912 4 года назад +7

    Thanks for the clear and straightforward explanation of this concept! The examples you used helped me understand builders a lot better.

  • @deependrajoshi199
    @deependrajoshi199 Год назад +2

    Beautiful article. Well explained, loved it. Thank you.

  • @KyleRebstock
    @KyleRebstock 3 года назад +1

    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.

  • @tubehelpr
    @tubehelpr 5 лет назад +10

    Great stuff buddy! Love these pattern explinations.

  • @SaminYasir-f3m
    @SaminYasir-f3m Год назад

    Great Explanation with examples! Keep it up, man!

  • @brijspy
    @brijspy 4 года назад +6

    Great stuff Kyle ! Loved these design patterns, keep up the good work :)

  • @kaicooper9421
    @kaicooper9421 2 года назад +1

    This is very useful. Perfect req fields

  • @unique_god
    @unique_god 2 года назад +2

    Imagine having builder class for every class taking care of super classes and child classes and composition

  • @yinonelbaz5309
    @yinonelbaz5309 2 года назад +1

    Thank you very much!!!

  • @cesarmuzio1154
    @cesarmuzio1154 3 года назад +1

    Thanks for sharing !

  • @helgestegemoen73
    @helgestegemoen73 Год назад

    Thanks. Trying to learn Builder Pattern in Java, and found your video very helpful 🙂

  • @GustavoFélix-f1d
    @GustavoFélix-f1d Год назад

    Simple, useful and very clear. Thanks man for that amazing content!

  • @DreQueary
    @DreQueary 3 года назад +1

    This is so slick. Very nice.

  • @luisrueda4476
    @luisrueda4476 2 года назад +1

    Good explanation!

  • @andersonlavor
    @andersonlavor Год назад

    The first one is builder pattern. Second example is called "named parameters" , you can use it in classes and functions.

  • @mahdisalem3776
    @mahdisalem3776 2 года назад +1

    whats the idea behind creating new class called UserBuilder , we can simply add all set methods inside the class user itself ?

  • @Q99a
    @Q99a 2 года назад +1

    Hi, why we've used build method in builder class ? Like what's wrong about using builder class.

  • @TheHuntingSpot
    @TheHuntingSpot 3 года назад +1

    where did you get that boomerang in the background?

  • @FluidEnjoyer
    @FluidEnjoyer 3 года назад +1

    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.

  • @alextipub
    @alextipub 4 года назад +1

    Thanks. Pretty nice explanation, subscribed

  • @moonshelter9137
    @moonshelter9137 4 года назад +2

    Thank you so much, well explained and all

  • @sankethb.k642
    @sankethb.k642 3 года назад +1

    Thank you. Can you please tell how did you linked live server to javascript

  • @fabioribeirodecarvalho2382
    @fabioribeirodecarvalho2382 3 года назад +1

    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

  • @GenerikV
    @GenerikV 2 года назад +4

    Really helpful. I was looking for python examples but the ones I found were making it bit too complicated, this was simple and precise.

  • @maheerali531
    @maheerali531 4 года назад +6

    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)
      }
      }

  • @jamshediqbal7936
    @jamshediqbal7936 5 лет назад +2

    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.

  • @barakatosalon
    @barakatosalon 5 лет назад +2

    Great video !!! Thanks for sharing this knowledge !

  • @deansprivatearchive
    @deansprivatearchive 3 года назад +2

    Shouldn't you use extends?

  • @yaseralamoodi8314
    @yaseralamoodi8314 5 лет назад +3

    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.

  • @davidjustice2323
    @davidjustice2323 4 года назад +2

    Kyle, how about using optional parameters like constructor(name?, age?) ?

    • @WebDevSimplified
      @WebDevSimplified  4 года назад +2

      By default every parameter in javascript is optional.

    • @davidjustice2323
      @davidjustice2323 4 года назад +1

      @@WebDevSimplified thanks for replying boss

  • @aryankumar87771
    @aryankumar87771 2 года назад +1

    is there a video on Factory Design Pattern ?

  • @rnater7145
    @rnater7145 2 года назад +1

    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)

  • @kinansharif5625
    @kinansharif5625 2 года назад +1

    Hey, can you say Backbone's way of initializing views and models, uses the second approach of the builder design pattern?
    Thanks !

  • @joeb.1163
    @joeb.1163 4 года назад +1

    Very good stuff

  • @techuchiha6510
    @techuchiha6510 5 лет назад +3

    Keep up the good work man!! Your channel is going to be epic one day 👍🏻👍🏻👍🏻

  • @zerobit778
    @zerobit778 2 года назад +1

    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~

  • @konstantinkkk8397
    @konstantinkkk8397 4 года назад +1

    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?

  • @3ab9ari1
    @3ab9ari1 4 года назад +1

    for the second methode is that available just in javaScript ? and why not for other languages ?

  • @shivabansfore7510
    @shivabansfore7510 2 года назад +1

    can we use this design pattern with react js?

  • @soniablanche5672
    @soniablanche5672 4 года назад +3

    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 ruclips.net/video/0GTe8e7DYHk/видео.html

  • @yaolegoleynik
    @yaolegoleynik 5 лет назад +1

    Thank you :) Need more pattern please

  • @Luxcium
    @Luxcium 3 года назад +1

    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)…

  • @technomaestro6092
    @technomaestro6092 3 года назад +1

    Can we do this with keyword arguments like **kwargs in python

  • @skalippanbalippan6972
    @skalippanbalippan6972 4 года назад +3

    Why don't we just put a setter and getter inside the User class?

    • @blank-vw2sb
      @blank-vw2sb 4 года назад

      It's pretty time consuming to write for every single property.
      AND
      I personally don't like that interface...

  • @mdsajaldeowan1054
    @mdsajaldeowan1054 4 года назад +1

    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

  • @emirsalihovic6616
    @emirsalihovic6616 3 года назад +1

    Kyle, can you do a design pattern series? :)

  • @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

  • @harag9
    @harag9 5 лет назад +1

    Interesting, thanks for this, but quick question - why no semi-colons? Are they not needed anymore in javascript?

  • @amjadshadid90
    @amjadshadid90 3 года назад +1

    thanks a lot

  • @praveengundla1235
    @praveengundla1235 4 года назад +1

    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)?

  • @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?

  • @usmaness
    @usmaness 5 лет назад +2

    Great video, I wonder if there is a way to implement builder like in JS with php, regardless the original way

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +3

      What do you mean? You can implement this pattern in any programming language of your choice.

    • @purduetom90
      @purduetom90 3 года назад +1

      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.

  • @imadetheuniverse4fun
    @imadetheuniverse4fun 2 года назад +1

    makes me really appreciate python kwargs

  • @elhamuddin.mahmoodi
    @elhamuddin.mahmoodi 5 лет назад +1

    Which theme is this in your VB Code
    I love it, plz name it.

  • @ivanpavlovnorth
    @ivanpavlovnorth 5 лет назад +1

    Really useful video!
    But resolution options are available in the only 360p.

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад

      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 5 лет назад

      ​@@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.

  • @r3boxx
    @r3boxx Год назад

    Where is the director. I am confused. I have seen other tutorials where they use something called a director.

  • @sagyas
    @sagyas 4 года назад +10

    Can't you just remove 'age' and 'phone' from the constructor, and put the Setters in the User class?

    • @baphnie
      @baphnie 4 года назад +3

      Exactly what I was thinking.

    • @arkilisx
      @arkilisx 3 года назад

      agree, quite misleading....

    • @m3awna
      @m3awna 3 года назад

      @Sagy Assor the reason is explained at the beginning of the video

    • @sagyas
      @sagyas 3 года назад +1

      @@m3awna 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 года назад +1

    Why can't we simply use named parameters?

  • @blackpurple9163
    @blackpurple9163 Год назад

    So this is like the state Hook in React?

  • @cleverengineer2410
    @cleverengineer2410 2 года назад

    You are a Legend.

  • @dudeimadolphin4318
    @dudeimadolphin4318 6 лет назад +1

    nice
    your doing so good man

  • @fiddler-dv4or
    @fiddler-dv4or 4 года назад +2

    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?

  • @TheHuntingSpot
    @TheHuntingSpot 3 года назад +1

    Maybe I'm old school but I like the having semicolons. What does everyone else think?

  • @quanghong3922
    @quanghong3922 5 лет назад +1

    awesome thank you

  • @jarwishroshan4298
    @jarwishroshan4298 2 года назад +1

    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? 😂

  • @d0paminer
    @d0paminer 3 года назад

    thx from Russia..!

  • @JimmyC0
    @JimmyC0 2 года назад +1

    Why don't we just put the setters method inside the user class with constructor having one parameter "name"

  • @WhiteSiroi
    @WhiteSiroi Год назад

    thank you

  • @abdelrhmanshokr7546
    @abdelrhmanshokr7546 4 года назад +3

    when I use the build method it returns an undefined even though I did exactly as you did !!!

  • @natqe4049
    @natqe4049 6 лет назад +1

    Thanks

  • @shivammakwan6409
    @shivammakwan6409 6 лет назад +2

    cool...👍

  • @xBZZZZyt
    @xBZZZZyt 3 года назад +1

    //why not just do this:
    class User{}
    var user=new User();
    user.name="asd";
    user.address=new Address("1","main");

  • @donnytechiera957
    @donnytechiera957 5 лет назад +4

    Bro you make coding simplified !!

  • @idev6775
    @idev6775 3 года назад

    thank you so muchh

  • @Vibestr
    @Vibestr 4 года назад +3

    builder pattern is confusing w/ all those "this' keywords.

    • @fredianriko5648
      @fredianriko5648 4 года назад

      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.

  • @mattmaloney5988
    @mattmaloney5988 3 года назад +3

    Please do a hair styling tutorial.

  • @NitinKatiyarCircle
    @NitinKatiyarCircle 5 лет назад +2

    Its painful when you write code without semicolon 😨

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +2

      Semicolons aren't needed and only make the code messy in my opinion.

    • @NitinKatiyarCircle
      @NitinKatiyarCircle 5 лет назад +1

      @@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.

  • @Ali-mc4le
    @Ali-mc4le 4 года назад +3

    Please tell me you work at google? You are damn good. Thanks for explaining this.

  • @guitarboy12
    @guitarboy12 4 года назад +1

    Why can't a C++ Builder Pattern be this simple? haha

  • @olegsuprun7590
    @olegsuprun7590 4 года назад +2

    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

  • @valentinrafael9201
    @valentinrafael9201 7 дней назад

    POV: how to get a 500 words line in js

  • @largo17
    @largo17 2 года назад

    You should really use console.table() for these examples :)