Observer Design Pattern in Javascript | Design Patterns Tutorial

Sdílet
Vložit
  • čas přidán 10. 11. 2017
  • 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

Komentáře • 61

  • @estengrove3350
    @estengrove3350 Před 5 lety +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  Před 5 lety

      Mate, no worries!

    • @estengrove3350
      @estengrove3350 Před 5 lety +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 Před 6 lety +13

    Clean explanation with a perfect example. Thanks for sharing.

  • @kcapt96
    @kcapt96 Před rokem

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

  • @faridul.hassan
    @faridul.hassan Před 6 lety +7

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

  • @cristianquintero288
    @cristianquintero288 Před 4 lety +3

    This is so amazing, please make more like this!

  • @salamina_
    @salamina_ Před rokem

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

  • @raymondmichael4987
    @raymondmichael4987 Před 4 lety +1

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

    • @dcode-software
      @dcode-software  Před 4 lety

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

  • @luisgabriel84
    @luisgabriel84 Před 4 lety +3

    Crystal clear my friend! Great explanation

  • @angelrivera4491
    @angelrivera4491 Před 5 lety

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

  • @user-tc3sh9pl4e
    @user-tc3sh9pl4e Před 4 lety +1

    It's really helpful! Thank you for posting.

  • @eyalshnitzerful
    @eyalshnitzerful Před 6 lety +2

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

    • @dcode-software
      @dcode-software  Před 6 lety

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

  • @KostaTsourdalakis
    @KostaTsourdalakis Před 5 lety +1

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

  • @sfsf285
    @sfsf285 Před 2 lety

    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

  • @killerjohn7577
    @killerjohn7577 Před 5 lety +1

    Great example!

  • @Skay5899
    @Skay5899 Před 4 lety

    Brilliant Example :-) Wel Done!!

  • @abdulkadirguven1173
    @abdulkadirguven1173 Před rokem

    Very useful tutorial.Thanks a lot.

  • @kbms7636
    @kbms7636 Před 5 lety +2

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

  • @damonwu9658
    @damonwu9658 Před 5 lety +1

    Nice shot !!!

  • @mehrane6344
    @mehrane6344 Před 5 lety +1

    Awesome tutorial. thanks mate

  • @adrianoqwe32
    @adrianoqwe32 Před 5 lety

    Wow!!! I got it. Thanks!

  • @baranidharanmurali469
    @baranidharanmurali469 Před 5 lety +2

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

  • @evgenylevchenya8734
    @evgenylevchenya8734 Před 2 lety

    Nice one

  • @philmirez
    @philmirez Před 5 lety +1

    👍 Great video.

  • @twsaif
    @twsaif Před 2 lety

    very helpful ❤️ thanks

  • @shendilkumar6922
    @shendilkumar6922 Před 5 lety +1

    Nice explanation 👍

  • @anselminos5238
    @anselminos5238 Před 4 lety +2

    thanks!!!

  • @marcoklein1754
    @marcoklein1754 Před 5 lety +1

    very good example

  • @tuyipato9033
    @tuyipato9033 Před 6 lety +1

    brilliant

    • @dcode-software
      @dcode-software  Před 6 lety

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

  • @ellsonmendesYT
    @ellsonmendesYT Před 2 lety

    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 Před 3 lety

    great

  • @muhammedozalp
    @muhammedozalp Před 4 lety +1

    thank you

  • @hossamadel7290
    @hossamadel7290 Před 5 lety +1

    thanks a lot

  • @worldofafrontenddeveloper9187

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

  • @kresimircosic3753
    @kresimircosic3753 Před 4 lety +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

  • @marinosterbah1883
    @marinosterbah1883 Před 2 lety

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

  • @bharath081991
    @bharath081991 Před 5 lety

    Thanks for tutorials. Please make code available to download.

  • @carry-on-chaos4032
    @carry-on-chaos4032 Před rokem

    can you show simple mvvm with js ?

  • @farouktouil5036
    @farouktouil5036 Před 3 lety

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

  • @aram5642
    @aram5642 Před 3 lety

    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.

  • @kostas_x
    @kostas_x Před 5 lety

    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!