Observer Design Pattern in Javascript | Design Patterns Tutorial

Поделиться
HTML-код
  • Опубликовано: 9 сен 2024
  • In this video I take you through a way we can implement the Observer Pattern using Javascript.
    The Observer Pattern works by defining a model and then a bunch of other dependencies (observers) on that model - so that when the model changes state, all the dependencies are notified of the change.
    You will be developing a page with a button, when the button is pressed a number is incremented and a color is chosen at random - the number and color change are represented in the HTML page itself and the console.
    This was inspired by java.util.Observer and java.util.Observable.
    If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
    #dcode #javascript #webdev

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

  • @estengrove3350
    @estengrove3350 5 лет назад +6

    This freakin' concept has been lingering at the tip my fingertips for so long, it felt like. But this video just solidified it using a clear and concise example. Killing it dcode! Thanks

    • @dcode-software
      @dcode-software  5 лет назад

      Mate, no worries!

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

      @@dcode-software It'd be really awesome if you did a series on JS design patterns series. I'm not sure if that's been asked before. But, it'd be greatly helpful.
      A lot of online resources tend to have some an overly technical approach that further complicates already complex topics. But, I think your teaching style would suit such a series well.

  • @santuparashetti
    @santuparashetti 6 лет назад +13

    Clean explanation with a perfect example. Thanks for sharing.

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

    One of the best explanations of the Observer Design. Congrats dude!

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

    Great example. This explanation really helped me on the observer pattern . Thank you

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

    very clear and clean explanation, finally someone who uses humanely logical classes and constructors in their javascript code not the regular JS stuff like prototypes and function objects or whatever that javascript disgusting mess is

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

    Crystal clear my friend! Great explanation

  • @faridul.hassan
    @faridul.hassan 6 лет назад +7

    Very clear to understand and really very helpful. Thanks for the video :)

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

    This is so amazing, please make more like this!

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

    Very useful tutorial.Thanks a lot.

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

    Clear explanation pattern, first to see your channel and subed already.
    Greetings from Tanzania 🇹🇿

    • @dcode-software
      @dcode-software  5 лет назад

      Hey, I'm glad you took something from this video - and welcome to the channel 😁

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

    Excellent , no doubt this is one of the best for Observer Pattern , will you make more Design Pattern Tutorials maybe in Udemy

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

    Super helpful! Dcode is the best!😍😍😂😂👌👌

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

    very helpful ❤️ thanks

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

    This video is amazing dude !!! thank you so much !! very good explanation !!

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

    Thank you for the video.Can anyone tell me if Promise can be called as an implementation of observer pattern ?

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

    Nice one

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

    Pro level explanation..
    New to your channel subscribed..😋

  • @user-tc3sh9pl4e
    @user-tc3sh9pl4e 5 лет назад +1

    It's really helpful! Thank you for posting.

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

    Brilliant Example :-) Wel Done!!

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

    Wow!!!!!!!
    Great example!
    Thanks a lot.
    Im gonna do something like that

    • @dcode-software
      @dcode-software  6 лет назад

      Yeah! Implementing your own Observer Patten for small apps/projects been be a really good alternative to a library such as Vue

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

    at 6:00 / 15:06 when I console.log model, I got this error : ReferenceError: NumberModel is not defined

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

    Great example!

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

    thank you

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

    Subbed. I am still kinda mediocre *OOP* user, but confusing thing for me was the schedule of information. For example, when you at near beginning used the *o.update(this)* on each observer. I was lost to why are you passing the instance of the *NumberModel* object inside the method. I thought that each observer will have their own *update* method which will do things - since they weren't yet made it confused me. Seeing them using actual information from the *NumberModel* instance made sense afterwards; but was like WTF why *this* inside the method... :) Thank you

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

    very good example

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

    Awesome tutorial and explanation, the only concern I found whas passing the model
    object to the observer, maybe passing just and object with the properties that have changed, this approach I found a little too ris
    ky

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

    great

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

    Awesome tutorial. thanks mate

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

    Nice shot !!!

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

    Nice explanation 👍

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

    Wow!!! I got it. Thanks!

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

    Nice but why would'nt a developer use dark theme ? especially for Atom

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

    thanks!!!

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

    👍 Great video.

  • @carry-on-chaos4032
    @carry-on-chaos4032 2 года назад

    can you show simple mvvm with js ?

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

    thanks a lot

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

    brilliant

    • @dcode-software
      @dcode-software  6 лет назад

      Thanks mate happy you enjoyed - it's a pretty good feeling discovering the Observer Pattern for the first time aye

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

    A very nice tutorial. Just one comment: I don't think o.update(this) is a good way of subscribing. It exposes the entire model to the subscriber, thus a subscriber could use all the methods of the model. So if possible, use the private accessor on the methods, or instead of passing 'this', just pass the properties that should be exposed.

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

    Thanks for tutorials. Please make code available to download.

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

    Here's the code for this video: minhaskamal.github.io/DownGit/#/home?url=github.com/kostasx/EventLoop/tree/master/javascript/design-patterns/Observer
    Really nice tutorial. Thank you for sharing!