8 Design Patterns | Prime Reacts

แชร์
ฝัง

ความคิดเห็น • 557

  • @NeetCode
    @NeetCode ปีที่แล้ว +607

    Holy shit, theprimeagen reacted to me! 🤯 Love it

    • @wlockuz4467
      @wlockuz4467 ปีที่แล้ว +24

      Thank you for 16:42 you damn comedic genius

    • @vidbina
      @vidbina ปีที่แล้ว +2

      You've made it! Keep that neet code (and those neet takes) coming. 🏆🥳

    • @yungifez
      @yungifez ปีที่แล้ว +1

      He just got you a new sub

    • @BurninVinyl
      @BurninVinyl ปีที่แล้ว

      Man, the Java joke was fantastic!

    • @ericbwertz
      @ericbwertz ปีที่แล้ว

      Whew, that one went your way... this time. :)

  • @betterinbooks
    @betterinbooks ปีที่แล้ว +416

    2:48 - factory pattern
    4:38 - builder pattern
    6:36 - -singleton- arch user pattern
    10:03 - observer pattern
    11:40 - iterator pattern
    14:21 - strategy pattern
    16:09 - adapter pattern
    17:56 - facade pattern

    • @codewkarim
      @codewkarim ปีที่แล้ว +6

      more like arch-user-ton patter :)

    • @peaked2258
      @peaked2258 ปีที่แล้ว +4

      Arch user pattern aka game developer pattern.

    • @blarghblargh
      @blarghblargh ปีที่แล้ว +15

      "strategy pattern" aka function pointer

    • @nexovec
      @nexovec ปีที่แล้ว

      @@peaked2258 UGH... no.

    • @rayquazaboladao
      @rayquazaboladao ปีที่แล้ว +3

      Façade

  • @ericm97
    @ericm97 ปีที่แล้ว +533

    Reasons I find these react type videos to be among the top best things to be happening to my career:
    1) I find out amazingly informative tech TH-camrs from the original videos
    2) Primes constant interjections is basically 100x-ing the information
    3) He’s so f*in funny.
    4) This kind of gold only seems to flow from highly technical senior engineers in the creamy layer of companies
    Thanks prime, continue to make these !

    • @heavenstone3503
      @heavenstone3503 ปีที่แล้ว +6

      Couldn't agree more !

    • @lookingjust987654321
      @lookingjust987654321 ปีที่แล้ว +11

      No offense to prime, and he's about as good an engineer as it gets. People that write business apps adopt the OO things because its useful in that context. engineering for large scale isn't the right context. I know people making $300k a year building salesforce apps, and $300k a year building large scale streaming systems. Context.

    • @jglaab
      @jglaab ปีที่แล้ว +13

      Constructive criticism: "Creamy Layer of companies" makes me uncomfortable 🥴

    • @TacoMaster07
      @TacoMaster07 ปีที่แล้ว

      Reason # 5) You have brain damage.

    • @Oi-mj6dv
      @Oi-mj6dv ปีที่แล้ว +1

      Agreed

  • @Lambda.Function
    @Lambda.Function ปีที่แล้ว +304

    Interestingly there are also functional programming patterns. I've got the full list here:
    1. Functions

    • @tablettablete186
      @tablettablete186 9 หลายเดือนก่อน +2

      I have been studying design pattern for some exams and this is just GOLD!
      Thank you for the laugh!😂

    • @johnmitchellvillanueva
      @johnmitchellvillanueva 9 หลายเดือนก่อน +2

      That is all you need

    • @sameeranadgaonkar9756
      @sameeranadgaonkar9756 9 หลายเดือนก่อน +1

      Lol, I'm studying design patterns after studying some functional programming and this is what I just realised. Strategy pattern == first class functions, visitor pattern == pattern matching!

    • @evergreen-
      @evergreen- 9 หลายเดือนก่อน +4

      True, Strategy pattern = higher order function, Iterator pattern = functor

    • @jkf16m96
      @jkf16m96 9 หลายเดือนก่อน +1

      Completely ignoring how functions can get other functions as an input, or even self-invoke them.

  • @sealsharp
    @sealsharp ปีที่แล้ว +227

    I love how some of the patterns are "wtf is that monstrosity" while others are "oh, that's a pattern? I thought that's basic doing things".

    • @hoi-polloi1863
      @hoi-polloi1863 ปีที่แล้ว +32

      That's how the whole "patterns" thing started... a bunch of 4 guys were just trying to codify good ideas they'd seen so they could share them around. Things then... well. Things got a little out of hand.
      MyClassFactory myClassFactory = new MyClassFactory();
      MyClass myClass = myClassFactory.create();
      BWA HA HAH AHA HAHAH AHAH AHAAA

    • @Lisekplhehe
      @Lisekplhehe 6 หลายเดือนก่อน +3

      I remember being asked which patter is a smart pointer in c++. I listed 3, before they told me it was a proxy and i was like yeah, i guess, but who cares?

    • @aameen951
      @aameen951 3 หลายเดือนก่อน +1

      Exactly, for example Singleton is simply a fancy name for a global variable!

  • @LogicEu
    @LogicEu ปีที่แล้ว +889

    So many religions in software nowadays

    • @iritesh
      @iritesh ปีที่แล้ว +12

      It's kinda weird ngl

    • @iritesh
      @iritesh ปีที่แล้ว +1

      Even IRL religions don't make sense, let alone software religions

    • @BboyKeny
      @BboyKeny ปีที่แล้ว +132

      Yeah, only religion that's valid it HolyC and TempleOS

    • @medaliboulaamail6491
      @medaliboulaamail6491 ปีที่แล้ว +15

      Alahuakbar

    • @kdot78
      @kdot78 ปีที่แล้ว +8

      @@BboyKeny long live the schizo god!!!!

  • @lorenzodrea4640
    @lorenzodrea4640 ปีที่แล้ว +12

    > Buys patterns book
    > Looks inside
    > Interfaces
    > 😐

  • @martinlutherkingjr.5582
    @martinlutherkingjr.5582 10 หลายเดือนก่อน +26

    Just realized 1994 is 30 years ago

  • @llave8662
    @llave8662 ปีที่แล้ว +52

    (he works at Netflix btw)

    • @esra_erimez
      @esra_erimez ปีที่แล้ว +7

      I wonder where he works

  • @icemojo
    @icemojo ปีที่แล้ว +151

    8:08 Well, as an avid Python programmer, I can vouch that while using decorators feels pretty nice (most of the time), writing them is an absolute mind numbing experience.

    • @ShadowKestrel
      @ShadowKestrel ปีที่แล้ว +27

      same goes for rust macros: I love when they are provided but now I am writing them my sanity is simply not here any more

    • @BboyKeny
      @BboyKeny ปีที่แล้ว +4

      @@ShadowKestrel I'm doing the proc_macro workshop and doing the derive(Builder) macro as my first 1 since yesterday.
      It's all fun and games, till I got to the optional-field part. I shudder at the realization that there are so many way to make a struct field optional and I would need to check all of them.
      I'm just starting out with it so there are without a doubt tons of pattern and tools to help with these kind of things that I don't know of.
      Although do think it's probably a very useful tool to have in my arsenal and way more powerful than macro_rules.

    • @ThatOpinionIsWrong
      @ThatOpinionIsWrong ปีที่แล้ว +21

      Me: "How does decorator work behind the scenes?"
      Senior dev: "It just works"

    • @greglocker2124
      @greglocker2124 ปีที่แล้ว +4

      ​@@ThatOpinionIsWrong with a smile on its face, that's how!

    • @Maric18
      @Maric18 ปีที่แล้ว +1

      how a decorator works:
      you write a function that takes in a function and gives back the "same" function
      plus you can do code on the side
      def print_instead(func):
      return print
      will give you a decorate that replaces the decorated function with print :D

  • @DryBones111
    @DryBones111 ปีที่แล้ว +60

    I too love the strategy pattern. Higher order functions are the most beautiful way to do the strategy pattern. Functional programming is just the strategy pattern all the way down. I love the strategy pattern btw.

    • @iambilbobaggins1884
      @iambilbobaggins1884 ปีที่แล้ว +10

      Do you love the strategy pattern?

    • @Gamester1128
      @Gamester1128 ปีที่แล้ว +12

      @@iambilbobaggins1884 I think he loves the strategy pattern... Can he confirm?

    • @ericbwertz
      @ericbwertz ปีที่แล้ว +3

      @@Gamester1128 I, too, wish I knew how he felt about this, and where/if he works.

    • @Hytpu9
      @Hytpu9 ปีที่แล้ว +6

      i was a bit confused at the begining of your message - does he rly love the strategy pattern, but at the end I put aside my doubts - you DO LOVE STRATEGY PATTERN!

    • @vikingthedude
      @vikingthedude ปีที่แล้ว +3

      Bro. I think you love the strategy pattern

  • @norcal6181
    @norcal6181 ปีที่แล้ว +12

    The pattern of choice at my job: The Spaghetti Pattern

  • @purdysanchez
    @purdysanchez 2 หลายเดือนก่อน +1

    Builder and factory are just semantic variations on a constructor. Builder just turns parameter assignments into individual functions that can be chained together.

  • @highlanderdante
    @highlanderdante ปีที่แล้ว +150

    are we going to just ignore the fact that he's using camelCase on Python?

    • @tablettablete186
      @tablettablete186 ปีที่แล้ว +10

      ​@Chase Miller snake_case >>>>> everything else

    • @judewaide8328
      @judewaide8328 ปีที่แล้ว +16

      ​@@tablettablete186 camel case is the only way

    • @tablettablete186
      @tablettablete186 ปีที่แล้ว +3

      @@judewaide8328 oBjEcTivALy WRONG!!! 😤
      (I wanna where this goes 😅😅😅)

    • @judewaide8328
      @judewaide8328 ปีที่แล้ว +1

      @@tablettablete186 lol

    • @jamesgood7894
      @jamesgood7894 ปีที่แล้ว +10

      @@tablettablete186 snake_case gang

  • @onelastkiwi8041
    @onelastkiwi8041 2 หลายเดือนก่อน +1

    i really didnt know that prime worked at netflix, im glad he mentioned it 10 times

  • @mechantl0up
    @mechantl0up ปีที่แล้ว +3

    I use the builder pattern for all my JS Web Components. I am surprised people are surprised at returning this. It works nicely with a functional style, too, with a builder class whose final commit returns a DOM node and other methods return this. The web component then basically builds as one function call that when returned returns the ready component.
    You may get away with using not a single if else for a full and fully parametrised component with ES6 if returning this from each build method except commit. Listeners and any other features are just properties inserted with the builder as each sub component is described by joining build calls with the dot notation. The build tree will thus extrapolate to any complexity, as a component can always comprise any of the builds, which can comprise any builds, and so on, till the call stack returns to the top level and a full HTML component with any child components is returned, and is inserted in the DOM with the final commit. In theory, the whole web page could be built thusly.
    Prettier than some React stuff I have seen.

  • @axelfoley133
    @axelfoley133 ปีที่แล้ว +14

    Video: Screw too small for the hole.
    Primeagen: We've all felt this...
    Me: I thought the idea was you couldn't feel it.

    • @TehKarmalizer
      @TehKarmalizer ปีที่แล้ว

      You know what you should feel by knowing what you don’t feel.

  • @cerulity32k
    @cerulity32k 3 หลายเดือนก่อน

    Builder is my favourite. You can omit and add whatever you want, the depth and detail that you ask of the struct is (USUALLY) directly paired with the amount of chaining you do. You can go with defaults, specify a few parameters, add more if you need to, or you can do the equivalent of in-place initialisation (which although it may not be as performant unorganized unoptimised, compilers might recognise the simplicity of the chained functions and would be able to evaluate the code into an object literal).

  • @PasiFourmyle
    @PasiFourmyle ปีที่แล้ว +4

    TH-cam REALLY wanted me to watch this, popping up on my end screens and recommended list for like 2 weeks now. I finally watched it..... sadly I'm not far enough on my coding journey to have learned anything or understood what was going on other than the great Prime jokes🤣

  • @maxteer2800
    @maxteer2800 ปีที่แล้ว +18

    I'm gonna take a shot every time you mention you work at Netflix

  • @cas97553
    @cas97553 ปีที่แล้ว +33

    It would be cool to go through examples of patterns in rust. I haven't looked at the code for serde but it seems to use interesting patterns such as adapters to support different serialization formats.

  • @mattwilliams1844
    @mattwilliams1844 ปีที่แล้ว +16

    Singletons are really nice for hardware abstractions in embedded systems. For example I only want one instance of my keyboard structure, not 2 or 20.

    • @potaetoupotautoe7939
      @potaetoupotautoe7939 ปีที่แล้ว +4

      I actually want 20, one for japanese , English and macro all in 1 keyboard

  • @Santa1936
    @Santa1936 9 หลายเดือนก่อน +2

    Some of the patterns are so ubiquitous that you almost don't need to know them. Like I don't need to know that air is called air because I just breathe it naturally

  • @khhnator
    @khhnator ปีที่แล้ว +11

    the idea of patterns is great.
    how people found patterns and tried to put everything in a pattern shaped hole was not.
    specially when "patterns" became some sort of bizarre synonym of OOP

    • @avwie132
      @avwie132 ปีที่แล้ว +2

      When someone confused patterns with OOP and confused OOP with classes it is quite difficult to take them seriously

    • @ethanwasme4307
      @ethanwasme4307 ปีที่แล้ว

      ​@@avwie132i don't program, they come off pretentious at the least 😢

    • @spittylama
      @spittylama 5 หลายเดือนก่อน

      Why do you think that happened?
      My suspicion is that most Modeling languages focus on OOP.

  • @seans4290
    @seans4290 ปีที่แล้ว

    This is exploding my brain - ive had such a hard time listening to other peoples coding videos. Not this, im fully engaged. Thank you!

  • @doomguy6296
    @doomguy6296 ปีที่แล้ว +3

    Python decorators are the best. They are the easiest form I saw for metaprogramming. It is really easy to read and understand the logic behind them

  • @sealer1675
    @sealer1675 ปีที่แล้ว +1

    14:00 I don't think you're supposed to raise exceptions on regular functionality (reaching the end of the list)

  • @StuartLoria
    @StuartLoria ปีที่แล้ว

    First video from this guy that I like

  • @first-thoughtgiver-of-will2456
    @first-thoughtgiver-of-will2456 ปีที่แล้ว +2

    Iterators in java: sugar
    Iterators in Rust: honey
    Iterators in python: 8 year old stevia packet

  • @fedeanastasis7040
    @fedeanastasis7040 ปีที่แล้ว +30

    I'm just about to suggest in my project to start using a Factory for a single reason. We have 5 different classes that create the same object using a builder BUT it isn't clear how many fields of that class have to be set up(spoiler all of its parameters so always the complete builder). To isolate in a single place how the creation of that object has to be, enforce validations and ensure one of the fields that is a map is always created correctly depending on 1 of those 5 usecases. If not we will snowball into having distribuited the creation logic across multiple places

    • @CottidaeSEA
      @CottidaeSEA ปีที่แล้ว +10

      And *that* is what factories are made for. To unify and hide away complexity from the developer who shouldn't have to worry about that stuff, and you still need to have some unified way to create everything.
      Oh, and I dislike factories (honestly not too keen of builders either) so I have every reason to absolutely shit on them. It's just that in some cases they actually do make sense. They are simply abused to infinity and beyond.

    • @NihongoWakannai
      @NihongoWakannai ปีที่แล้ว +8

      @@CottidaeSEA i feel like this how it goes for a lot of patterns. We hate them because of how they get misused, but by god they are very useful in their actual niche.

    • @wadecodez
      @wadecodez ปีที่แล้ว +2

      don't use a builder or factory if instantiation params are wonky/unknown. you should consider writing a context object. then any methods/classes that have the wonky/painful params pull from a single source. you'll see this a lot in JS when working with large libraries. There will usually be a single settings object which describes how the library should behave.
      The key to keeping settings objects maintainable is making them immutable. Once you allow mutations to settings, you are no longer passing around context, you are passing around state. immutable context is predictable state is not.

    • @CottidaeSEA
      @CottidaeSEA ปีที่แล้ว +1

      @@NihongoWakannai Yeah, I feel like that also translates to OOP getting a lot of undeserved hate.

    • @CottidaeSEA
      @CottidaeSEA ปีที่แล้ว +1

      @@wadecodez Doesn't that pattern also use a factory? I've never seen it without a factory at least.

  • @hassan2868-u7q
    @hassan2868-u7q ปีที่แล้ว +1

    Dr.disrespect of programming

  • @c4tubo
    @c4tubo ปีที่แล้ว +1

    Common confusion: Observer is not Pub-Sub. Observers listen directly to their Observables/Subjects, so then each Observable/Subject must keep references to all of its Observers and become bound to their lifetimes. Publish-Subscribe adds one more level of indirection by having publishers and subscribers both depend directly upon a Channel between them; therefore they are tied to the lifetime of the channel rather than each other. Subscribers only become aware of publishers when notified with a message that provides the reference to the publisher if necessary.

  • @mattymerr701
    @mattymerr701 15 วันที่ผ่านมา

    All the patterns that seem simple and commonly used now show that these designs really were foundational.

  • @porky1118
    @porky1118 ปีที่แล้ว +1

    16:30 I recently had a similar problem.
    My solution was buying bigger screws.

  • @tech3425
    @tech3425 ปีที่แล้ว +10

    That casual "when I was at Google" also got me going "weird place to flex, bud" 😂

  • @kodekata
    @kodekata ปีที่แล้ว

    Great comment at 15:48 . From a functional perspective, the "interface" you are crying out for, is just a function.
    However I don't think it's worth a full fedora-tip here, because as competent engineers we need to be prepared for any situation we may walk into. Such as George Clooney walked into in From Dusk Till Dawn.

  • @TechBuddy_
    @TechBuddy_ ปีที่แล้ว +5

    I don't know why but I crave more of these 💓💓

  • @ProjSHiNKiROU
    @ProjSHiNKiROU ปีที่แล้ว +5

    Peak of OO culture: Implementing Strategy and Visitor patterns (I still can't implement the visitor pattern without looking it up).
    Peak of FP culture: Monad transformers

    • @wlockuz4467
      @wlockuz4467 ปีที่แล้ว +1

      I still don't know wtf is a monad.

    • @stdprocedure
      @stdprocedure ปีที่แล้ว +1

      @@wlockuz4467 SIMPLIFIED: it's a "wrapper", which takes closures/functions/lambdas which modifies the internal data (aka map function)
      It also needs a "pure/unit/wrap" function and also a bind/flatmap function.
      *Example without monads:*
      let person = Person { name: "John" };
      function print_name(person: Person) {
      if person != null {
      if person.name != null {
      print(person.name)
      }
      }
      }
      print_name(person);
      *Example with a monad (Option):*
      let person = Person { name: "John" };
      function print_name(person: Option) {
      person.map(p -> p.name).map(name -> print(name));
      }
      print_name(person);

    • @adambickford8720
      @adambickford8720 ปีที่แล้ว

      @@wlockuz4467 Instead of getting the data and applying your code to it (like a loop), you pass your code to the monad an IT will apply your code to the data. You just don't exactly know if, how or when cuz abstraction, which is the entire point. For example, in an Option/Maybe/Try monad your code will only be applied to the data if it exists.

    • @aoeu256
      @aoeu256 ปีที่แล้ว

      outside of Monad Transformers you have MTL, Lenses and for many types of programs instead of using MTL many people use Freer Monads/Extensible Effects. Also arrows

  • @JJ-hb9in
    @JJ-hb9in 11 หลายเดือนก่อน

    “Patterns” is just something to grab if you don’t have lambda, the ultimate abstraction

  • @alexcook4851
    @alexcook4851 ปีที่แล้ว

    love the design patterns book, great video!

  • @Leto2ndAtreides
    @Leto2ndAtreides ปีที่แล้ว +3

    I usually think about the Facade pattern in terms of delineation between groups of developers, or major functions in an app... But one could just consider it a part of UX (or DX) → You make stuff easier to communicate, understand, and use.
    I wouldn't think of it normally as an endpoint though - unless you were explaining the endpoint with docs in a "This is all you need to know to do this" sense.
    But I think that perspective comes from seeing Facades as typically being a class with clear features, and not just any point that simplifies interactions between one system and other systems.

  • @josephp1263
    @josephp1263 ปีที่แล้ว

    I love how straight to the point reactions Prime Reacts have

  • @holthuizenoemoet591
    @holthuizenoemoet591 ปีที่แล้ว +6

    the arch user strategy pattern sounds interesting

  • @0xCAFEF00D
    @0xCAFEF00D ปีที่แล้ว

    2:45
    I'm completely missing why the factory is a separate class and not just a set of static create functions on the burger. Am I just to imagine we're passing the factory somewhere to use as a customization point? So others can make the burger I want.
    This just feels like code obfuscation until you have a LOT of places where you instantiate burgers that all should be uniform or at least follow the standard as a baseline. Alternatively a very complex standard burger. But if that's all I still think the static method makes more sense.
    It also seems like a mess to have such diverse objects that don't express that in the type system. Code that operates on burgers with customization significant enough that you have to abstract away some complex init function must be very hard to operate on and it doesn't seem the code subdivides the problem enough. The example doesn't show that because it's too simple to even consider writing.
    5:00
    Even more confused now. The builder pattern doesn't seem to be replacing the factory.

    • @ACAndersen
      @ACAndersen ปีที่แล้ว +1

      It doesn't need to be a class in python, you can just make a factory function. Also the example is not ideal. The factory pattern usually instantiates different subclasses, with different internal implementations. Using the pattern for different sets of arguments is not the common usage that describes the pattern.

  • @kiffeeify
    @kiffeeify ปีที่แล้ว +5

    I think the Singleton pattern as just a special case of "execution contexts" where there is only one global context.
    It can simplify code by removing the need to explicitly pass down dependencies into the callstack.
    However, as with all static globals, it creates global coupling.
    staying with the python example from the video I would always rather use a construct as below instead of a singleton:
    ```python
    with some_context_of_type_y():
    with some_context_of_type_x():
    foo()
    def foo():
    y = get_y_object()
    x = get_x_object()
    ```
    IMHO it gives better composability on the outside scope and has the same advantages as singletons on the inside scope.

    • @ThomasZero288
      @ThomasZero288 ปีที่แล้ว

      Yea there are very few scenarios to actually use this pattern once you have DI, in fact it only interferes with/breaks DI. The only two examples I can think where I would actually use it are A) a tiny app where I'm not going to include an IoC library or B) In the very initial boot of your app when the IoC container/AppContext is either half constructed or has not finished initializing and is in an unsafe/incomplete state, yet you still need access to critical components like a preInit logger.
      Cause if AppContext fails to initialize... and that's where you get your logger from... and you want to log the error... and it IoC fails to initialize.... so you want to log it... but it has the..... wait.. where was I? where am i? WHO ARE YOU PEOPLE???? Can someone call my mom, im scared

  • @techsuvara
    @techsuvara 8 หลายเดือนก่อน

    Reactive programming works a lot with Observer, Iterator and Strategy patterns. For some historical insight, it's called RX because Microsoft did a lot of work with something called Reactive eXtensions, hence it evolved to RXJava.

  • @ISKLEMMI
    @ISKLEMMI ปีที่แล้ว +1

    8:25 - What is this contraption??
    16:18 - ngl this caught me off guard mid drink

  • @mchisolm0
    @mchisolm0 6 หลายเดือนก่อน

    Thanks for going over this. I feel like I must be missing something because I’ve watched this and Fireship’s video on it and feel like this doesn’t actually help me think about the way data can be structured or organized.
    I’m a high school teacher, so working on learning to relay the lessons to students in my CS classes. Thanks Prime. 😊

    • @spittylama
      @spittylama 5 หลายเดือนก่อน +1

      The main idea is to not reinvent the wheel every time a similar problem occurs. Back when the book came out, the idea was that software engineering was a relatively new discipline in comparison to e.g. engineering or architecture. So they started to look for standard solutions in patterns at the design or implementation stage of a project

    • @mchisolm0
      @mchisolm0 5 หลายเดือนก่อน

      @@spittylama Thank you. I do understand that’s the *purpose*; I’m saying I can tell I still have yet to understand the content.
      I have been working on building projects with data, but I’m not sure I see the patterns, yet. I hope that makes sense.

    • @spittylama
      @spittylama 5 หลายเดือนก่อน +1

      @@mchisolm0 patterns with data are even more recent! So no worries with that. The well established patterns often have a OO design approach.

    • @mchisolm0
      @mchisolm0 5 หลายเดือนก่อน

      @@spittylama do are you saying this is *not* about patterns with data? If so, I must have been really misunderstanding…

  • @MrAbrazildo
    @MrAbrazildo ปีที่แล้ว

    2:48, they just gave a name for a thing that has been made in C for decades:
    struct CheeseBurger { const char *ing_1, *ing_2, *ing_3 };
    #define createCheeseBurger CheeseBurger { "bun", "cheese", "beef-patty" }
    And then call it by:
    CheeseBurger a_cheese_burger = createCheeseBurger;
    5:20, this is a "lesser version" of C++ for 2 reasons:
    a) If 1 just wants to customize the initialization, C/C++ way is much better, as exposed above, due to compact syntax.
    b) If the goal is to customize it along the way, not only on initialization, it should has a control of which f() is allowed do that - _and it seems that only C++ has this feature_ . Otherwise, all sorts of bugs can come from it, because everything will be public, which is the worst nightmare, depending on the project complexity.
    10:57, why use an interface for that? Couldn't it be just a class? 16:00, again, why an interface? This thing is awkwardly slow!
    21:00, and that's why f() programming < OO: the 1st lacks good facades. In C, you can let that memory management "encapsulated" away in a different file. But there are issues:
    a) Each file like this will be dedicated to each object, which hurts scalability.
    b) If only 1 generic file like this is created, then the user will has to keep traveling alongside with that array, which is exposed to dumb mistakes for long unnecessary time.
    It's still possible to create several macros, trying to hide that array exposure, but it's still a precary solution.

  • @patrickshepherd1341
    @patrickshepherd1341 5 หลายเดือนก่อน

    Ngl... sometimes listening to the definitions of these named patterns,I feel like the next one is gonna be "and the Typing Pattern is where you press keys on the keyboard to put code in a computer!" "The Press Play Pattern is where you have to click a button to make your code run after it's written!"

  • @HrHaakon
    @HrHaakon ปีที่แล้ว

    I am convinced that the US has a different Java than the rest of us.
    The only place I know of that has abstract factories are frameworks like Spring.
    Because Spring can make a case for "I need to have a way of producing objects of whatever type specified", as well as "and I need to allow more than one way of doing it".
    And that's just because of the very generic way the IoC-container works.

  • @mrrolandlawrence
    @mrrolandlawrence ปีที่แล้ว

    12:50 i had the similar experience. Microsoft tried to hire me with a 40% cut of my city salary. They said oh but we do value you, we intend to hire you out to clients for $5000 a day. This was in 2000 when $5000 was still quite an impressive amount.

  • @hackmedia7755
    @hackmedia7755 3 หลายเดือนก่อน

    You could have a class called Food.
    It can be composed of an array of various ingredients and include a name variable.

  • @ov1kenobi663
    @ov1kenobi663 ปีที่แล้ว +1

    4:20; Composition over Inheritance

  • @porky1118
    @porky1118 ปีที่แล้ว

    8:00 No, if used like this, singeltons are pretty stupid. I just use them when I can't have global state, or I don't have control over the main function or something similar. (only in Unity)
    And I never define a static method when using them. I just use a public static parameter, or different static methods to access it.

  • @zerosandones7547
    @zerosandones7547 ปีที่แล้ว +1

    beginner question:
    what's the difference if I just use: new Burger("bun-type", "patty-type", "cheese-type"); vs the builder pattern?

    • @zachmanifold
      @zachmanifold ปีที่แล้ว

      The main difference is if there's a varying amount of options when building an object.
      Say that I'm a really weird person and only want a burger with only a bun (no patty or cheese). Then I can use burger = BurgerBuilder().addBun().build()
      Or if I only want bun with cheese (no meat), burger = BurgerBuilder().addBun().addCheese().build()
      Otherwise you'd need several different constructors to handle every possible combination (which quickly gets messy when multiple options are involved.)
      The burger example is not the greatest to show this difference but hopefully that made some sense

    • @aoeu256
      @aoeu256 ปีที่แล้ว

      the code is in Python but you used the new keyword hahah. You don't need builder in Python cuz of default arguments, keyword arguments and dicts in Pythons.

    • @zerosandones7547
      @zerosandones7547 ปีที่แล้ว

      @@zachmanifold ooh,, now that you said something about those constructors, I got it now, thanks! :)

  • @stephenreaves3205
    @stephenreaves3205 ปีที่แล้ว +6

    How are decorators different from derive macros in rust?

    • @nickbanderson
      @nickbanderson ปีที่แล้ว +12

      One is RUST and the other is NOT RUST

    • @Ether_Void
      @Ether_Void ปีที่แล้ว +8

      There are a few differences.
      For one derive macros can only be used on types (struct, enum, union), they see the definition and return the implementation for a certain trait and can't really do much else.
      Rust also has attribute macros which are less often used but they are a bit more similar to decorators. However Rust macros will always run at compile time and work on the syntax tree, where Python decorators run at runtime and work on class or function instances.
      Since the decorators in Python are running at runtime, they can already call functions and access attributes in the classes which isn't really possible with macros in Rust.

    • @ariseyhun2085
      @ariseyhun2085 ปีที่แล้ว

      I'm a rust fanboy, but true.. they're pretty much the same tbh

  • @akirakosaintjust
    @akirakosaintjust ปีที่แล้ว +2

    Observer, Iterator and Strategy are great. Singleton is ok if you're careful with state (Rx singleton Observable for instance). Adaptor and Facade are unavoidable, but I hate how coupled they can get. Factory and Builder are meh - I feel they're needed sometimes but they get overused. ps. lol at Primer reacting to Python OOP in real time

  • @TheNewton
    @TheNewton ปีที่แล้ว +1

    Developer-Experience is the missing pattern category.
    17:55 Facade is a DX pattern for every clean http endpoint , convenience functions , the porcelain over the plumbing.

  • @hamzahmd_
    @hamzahmd_ ปีที่แล้ว

    I first thought it was about PrimeReact UI Library.
    Your videos are fun to watch; I've subscribed.

  • @AceofSpades5757
    @AceofSpades5757 ปีที่แล้ว +21

    Decorators are one of my favorite things about Python. They're so fantastic.

    • @banatibor83
      @banatibor83 ปีที่แล้ว

      One of the most useless language feature :) They have very limited use if you do not want to end up with totally unreadable code.

    • @grantpeterson2524
      @grantpeterson2524 ปีที่แล้ว +2

      I used to dislike decorators, but I'm currently working in C# (which doesn't have them) and I keep running into instances where it would be really nice...
      I have a class that makes API calls asynchronously, but I need to limit the number of async calls being made at a time. So, I need to use a semaphore to force threads to await if all the other threads have used up the semaphore. Would be super nice to just use a decorator at the top of every method that makes an API call so that it wraps the execution with an await to the semaphore, but not an option for vanilla C#. I ended up creating another class called RequestExecutor that has methods that take lambda functions and do this instead, but it feels less clean.

    • @aoeu256
      @aoeu256 ปีที่แล้ว +1

      @@banatibor83 If you think decorators are bad, what about the abstractfactory patterns here. They are used for black-box aspect oriented programming to simplify your code, and are in JavaScript as well.

  • @JohnWasinger
    @JohnWasinger ปีที่แล้ว

    17:45 Adapter pattern is just the application of a strategy pattern.

  • @MEZOMEZO2011
    @MEZOMEZO2011 6 หลายเดือนก่อน

    What is the iterator pattern?
    14:11
    It's just a loop!

  • @v1Broadcaster
    @v1Broadcaster ปีที่แล้ว

    this channel is my favorite netflix advertisement

  • @DuRoehre90210
    @DuRoehre90210 10 หลายเดือนก่อน

    11:00 Yeah, yeah, but there are languages *cough* where managing the lifetimes of the subscribers kept in the list can cause you a lot of trouble, and even using smart pointers might not save your day in cases where certain strange runtime dependencies in the destructors cause race condition or some runaway loops or similar fun. And yes, Facade is not an actual pattern of it's known, it's only a special case of the Wrapper.

  • @T1Oracle
    @T1Oracle ปีที่แล้ว +2

    The only reason to use a factory is to hide the complexity of object creation. If a design pattern does not result in simpler code, then you are using the wrong design pattern.

  • @armynyus9123
    @armynyus9123 ปีที่แล้ว

    As a netflix btw guy Prime could/should have really said a bit more about the observer pattern. ReactiveX was a live changer for me, and that netflix talk about it sold it to me, back then.

  • @MihoKozloffsky
    @MihoKozloffsky ปีที่แล้ว +2

    The idea of a factory is to provide only one interface create so client class could use it to create object of given interface. Like when you need some default value (like in data classes) when constructing object.

    • @karlsassie8403
      @karlsassie8403 10 หลายเดือนก่อน

      You mean like a function 😅

  • @jma42
    @jma42 ปีที่แล้ว +1

    im a bit new to design patterns, and ive been struck into the type state pattern from rust, is type state pattern also a form of builder pattern?

  • @CamembertDave
    @CamembertDave ปีที่แล้ว +2

    Builder isn't "better" than factory, they are just suited to different circumstances - builder for flexibility; factory for simplicity. E.g. a library class uses builders in order to provide maximal functionality, but an app using that library wraps this in a factory to provide a simpler interface for the small number of specific uses its needed for in that app.

    • @ThePrimeTimeagen
      @ThePrimeTimeagen  ปีที่แล้ว +1

      I just tend to find that factories are not what I want, yet. That's what I find myself doing. But a builder almost universally is what I want. Oftentimes you can even interchange them and I find the results almost always better with builder and a good setup defaults

    • @TehKarmalizer
      @TehKarmalizer ปีที่แล้ว

      I agree with Prime. I’ve never liked factories. They aren’t as flexible as builders.

  • @mattymerr701
    @mattymerr701 15 วันที่ผ่านมา

    Is the strategy pattern just more complicated higher order functions?

  • @jogewe
    @jogewe ปีที่แล้ว +4

    I loved head first design patterns 🥰

    • @akshay-kumar-007
      @akshay-kumar-007 ปีที่แล้ว +2

      The book is just so awesome. The way they teach design pattern by first introducing the problem and slowly building up the solution is great!

  • @porky1118
    @porky1118 ปีที่แล้ว +3

    15:00 That's why I hate pattrens. They give things I do everyday, which aren't special to me, names, and call them patterns. And I'm supposed to know these patterns now.
    I had no idea what the strategy pattern is. I just pass functions to make my code more generic and that's it.

    • @sch3me521
      @sch3me521 10 หลายเดือนก่อน +1

      I feel the same way. They're patterns in the sense that they appear a lot but I think the moment you start naming then and teaching useless toy examples to people they go from "common problem solving technique" to "tool I need to know and fit in my code somehow". I swear software engineering is the worst thing that has ever happened to programmers

  • @Mr.MattSim
    @Mr.MattSim 11 หลายเดือนก่อน

    Facade = Noise Adapter
    Adapter = Interface Strategy
    Strategy Pattern = interface.method(strategy) = noun.verb(how)
    Adapter = noun2.verb(noun1.verb(how))
    Facade = () => noun2.verb(noun1.verb(how))

  • @DagarCoH
    @DagarCoH ปีที่แล้ว +1

    Saw the original before, generally good comments as far as my experience with these patterns go.
    One critique I have is your statement that "Everything is a facade, becaus you hide information" with something something private. Facade does obfuscate variables and functions from the programmer, but they are still accessible from the outside. Basically, Facade (at least as stated in the GangOf4) is an interface to a functionality that says "Hey, 99% of the time, you will want to use me by calling these couple of functions here. If you need more custom behaviour and you REALLY know what you are doing, you can also tweak all my other variables and use these other functions". So Facade gives you a set of convenient functions to use it with, but also allows for access to everything else about the interfaved functionality, if you want to.

  • @xBZZZZyt
    @xBZZZZyt ปีที่แล้ว

    03:56 why put functions in class BurgerFactory instead of global?

  • @porky1118
    @porky1118 ปีที่แล้ว

    19:00 I expected facade being something like "struct NodeId(usize);"
    Internally it's just an integer, but you can't use it like an integer.

  • @FaceBookAutomated
    @FaceBookAutomated ปีที่แล้ว +1

    Can you dump full vods as well? I’d like to re-experience everything from the stream.

  • @sphesihlemanuel2933
    @sphesihlemanuel2933 ปีที่แล้ว +2

    Bro I watch your videos everyday huge respect . I learn lot here .

  • @akam9919
    @akam9919 ปีที่แล้ว

    That opening was like a man confessing adultery to his wife.

  • @htrOfLiesfub
    @htrOfLiesfub ปีที่แล้ว +2

    This video was good. Why? We learnt something, unlike some videos where you just rant or do irrelevant optimisations, in this I actually learnt something which can get someone hired.

    • @ericbwertz
      @ericbwertz ปีที่แล้ว

      Rant material is often a flash-forward to a problem or conflict that you just haven't run into YET -- artifacts of some clear, prior trauma.

  • @nandomax3
    @nandomax3 ปีที่แล้ว +1

    I love the builder pattern, it's so useful. And the factory pattern is also super helpful

    • @aoeu256
      @aoeu256 ปีที่แล้ว

      In Python keyword arguments and dictionaries tetrisgame(func1={arg1: 5}, object2={arg2: object3}) can replace builder pattern...

    • @SAsquirtle
      @SAsquirtle ปีที่แล้ว

      ​@@aoeu256can you elaborate?

    • @TheEVEInspiration
      @TheEVEInspiration ปีที่แล้ว

      It is only useful when you need to control what actually gets instantiated or how it gets configured during or after constructing.
      In all other cases, just doing a "new" of the proper class is both simpler and easier to follow.
      So if there is this need, sure, go for it.
      But I will never consider it a pattern to default to.

  • @FredoCorleone
    @FredoCorleone ปีที่แล้ว

    "Can we pause for a second? I hate decorators"
    Hahahahaha

  • @Leto2ndAtreides
    @Leto2ndAtreides ปีที่แล้ว

    "btw, I work at Netflix"...
    "Oh, you work at Netflix? Why don't you ?"
    lol

  • @kayakMike1000
    @kayakMike1000 2 หลายเดือนก่อน

    Decorators are GREAT!!!

  • @lethicanthus
    @lethicanthus ปีที่แล้ว +5

    Design patterns in functional programming:
    strategy pattern: functions
    builder pattern: functions
    observer pattern: functions
    adapter pattern: believe it or not also functions

    • @aoeu256
      @aoeu256 ปีที่แล้ว +1

      Builder pattern is record syntax + functions, adapter is record of functions.

    • @evancombs5159
      @evancombs5159 ปีที่แล้ว +1

      Functional programming uses functions instead of objects, this checks out.

  • @IgorGuerrero
    @IgorGuerrero ปีที่แล้ว +1

    Did I hear I hate decorators? How do you love this though? #[Derive(Debug,Clone,Display)] on all your structs? :)

  • @dw8211
    @dw8211 ปีที่แล้ว

    9:50 "shared mutable state is the bane to all programming and the key to super awesome amazing performance and it is the scariest thing in the universe...so...careful."

  • @tricky2014
    @tricky2014 ปีที่แล้ว +2

    The implementation of the linkedlist iterator in the video is actually faulty. If you would create two iterators they would actually both modify the object.

  • @ElderSnake90
    @ElderSnake90 ปีที่แล้ว +3

    Close your eyes and listen and you half expect Prime to throw out a random "Morty" during his speeches. Y'ALL KNOW I'M RIGHT (seriously though if Prime wasn't a software dev he could probably take over for Rick's VA)

  • @SuperKhezar
    @SuperKhezar ปีที่แล้ว

    8:45 - what is prime holding?

  • @robgrainger5314
    @robgrainger5314 ปีที่แล้ว +1

    Where did you work again? Was it Prime Video?
    (ducks)

  • @shaunmolloy_
    @shaunmolloy_ ปีที่แล้ว

    Laughed at the, "is this bash now!?" comment 😂

  • @seyofori
    @seyofori ปีที่แล้ว

    😂😂😂😂😂😂😂
    goodness... I laughed so hard at the Adapter pattern. 16:09

  • @naranyala_dev
    @naranyala_dev ปีที่แล้ว

    Top tier dev reaction videos 🌟🌟🌟🌟🌟

  • @henrykkaufman1488
    @henrykkaufman1488 ปีที่แล้ว

    When I try Observer i end up with events of things that happened in reaction to some other event and stuff happening in random order and it turns out order matters and everything goes to sh*t what am I missing?

  • @ajtan2607
    @ajtan2607 ปีที่แล้ว

    "I work at Netflix btw"
    has similar vibe as
    "I use Arch btw"

  • @thirdvect0r
    @thirdvect0r ปีที่แล้ว +1

    builder pattern with rust is good because of the TypeState Pattern

  • @TECHN01200
    @TECHN01200 ปีที่แล้ว

    On the last point of the facade pattern, NeetCode says "you don't want to think about memory allocation" and here I'm thinking "it isn't difficult at all, there is this thing called realloc." The only reason why it sucks in java is because java does precisely this, remove any need for you to think about memory allocation. Realloc is a better abstraction than java.

  • @mitrichaka11
    @mitrichaka11 ปีที่แล้ว

    So what kind of company do you work in?