How To Reduce Coupling With Facade | Design Pattern Tutorial

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

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

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

    👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis

  • @stonebam4611
    @stonebam4611 2 года назад +12

    Your videos, especially on coupling, are really great! This series helped me so, so much beeing a better developer! Thank you very much!

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

      Thanks so much, glad the content is helpful!

  • @mamazu1995
    @mamazu1995 2 года назад +9

    The facade pattern is a good pattern and you explained it well. But I think a better example would have been if you had abstracted away the IOTSpeaker as a class. Then the object would just have an on, off and maybe toggle function which hide away the complexity of the interaction with the speaker. And this would also make it much easier to add more speakers later on.

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

      Yep, I was expecting to see protocol at some point as well

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

    Excellent, I've been throwing the word "Facade" around recently in my design for an Android App... This video popped up in my RUclips suggestions and I thought I'd better revisit it to make sure I'm not embarrassing myself. :)

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

    I would love to see another device to this code as a follow-up to see the more long-term benefits of this.

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

    I think that all these patterns do really achieve practical "simplification" when the code refactoring is documented with a class/module diagram.
    Another thing to understand is that rather than "simplifying" the existing code (as in "it is now simpler to understand the program as a whole"), it simplifies its maintenance, makes it more evolvable, etc.
    Many developers will find the initial code easier to understand than the final one, even though the final code is conceptually "cleaner". That is because, to understand the latter, you need to implement a "stack" of calls in your head.

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

    I wasn’t aware of the partial function. Nice one!

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

      Thanks so much, glad the content is helpful!

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

    Love the design patterns content!

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

      Thanks Mikko, Glad you like them!

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

    Hi Arjan! As always great and helpful content.
    I am a recent graduate who just started a new job. As of now, my main object in this job is to read the code base and understand the system. However, I find it quite overwhelming to go through heaps of codes. Although the code is written well (modular and well organized), I am finding it difficult to piece them together to understand the bigger picture. I find it easy to understand functions and classes that have no dependencies, but I can't get my head around with classes and functions with dependencies (and the difficulty seem to increase exponentially if the number and levels of dependencies increases. I think the obvious solution would be to build my way up from classes that don't have any dependencies but that's sometimes not feasible if the code base is huge). I would really appreciate it if you could make a video of how to read code from huge code base (by may be looking at a huge open source repo).

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

    Personally, this made the benefits of MVC obvious, but it was still hard to see the benefit of the facade. I think this is because you showed how you could change the controller without changing the gui, but there was no concrete example of what you’ve now decoupled with the facade. I’m sure if I watch it slower and think hard about your words then I would figure it out. But that’s not typically what I enjoy about your videos.
    Still a nice and lighthearted and fun experience. Just a little harder to learn from in my opinion.

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

    Thanks for the video Arjan! When you create IOTFacade is there any particular reason you don't use dependency injection for SmartSpeakerDevice() but you create it inside the init method instead?
    Also, I assume the controller functions could also be part of a separate class, e.g. Controller? Then we could use composition in a way that the Controller class owns an instance of IOTFacade.

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

      About the second question. He says about it in the video. He prefers partial functions because they can possibly be moved into separate files. But the class is OK too.

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

      @@ego_rod Yeah figured this out in the meantime, I was writing the comments while I was watching the video :D

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

    I love the videos on patterns especially in combination with some examples, so this is another great one imo. However, I must admit that the delivery of the joke in the intro rivals the content. I don't know what it was, but it had me in stitches :D
    Keep up the great work!

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

      Thanks M. Coelho, happy you’re enjoying the content!

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

    Wow, I started watching this wondering if it might be something I'd like to implement in a big project I'm currently working on and it turns out the design I have currently implemented is pretty much exactly this.

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

      Haha, always love that when it happens :).

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

    Great video as always !
    What if you would also have temparature sensor that periodically triggers specified callback function with the current value of the temparature as an argument. How would you connect this callback to update value in the UI window? I imagine IOTFacade would require additional argument that expects a function that is called with the temparature value, everytime the sensor sends it. But as you create UI (SmartApp) once the IOTFacade is already created, you cannot pass the SmartApp's method, that would update UI with new temparature value, to IOTFacade. Basically my question is, how to connect signals that come from IOTFacade towards SmartApp class.

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

    Hello. Thank you for your videos. I appreciate the beat software engineering coding practices you present. Any recommendations regarding code that is meant to interface a command line tool with other formats? How should the commands to the command line tool should be stored? In a dictionary... Perhaps each command in a function/method? Thank you in advance.

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

    totally love the video! I’m just curious about this but do you ever use your editor or IDE’s re-factoring functions or do you always just re-factor manually?

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

    I'm a novice level programmer so I must admit I was confused by the functions 'power_speaker' and 'get_status' in iot_controller.py. These functions depend on the IOTFacade class which has methods of the same name which are called within the functions. At first it felt kinda circular but then I realized the functions are just wrappers around the IOTFacade methods. I'm slowly understanding this is part of decoupling the lower level functionality from the gui. I wish I had known about this a year ago... but it's never too late.

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

    You said you;d use a separate function to create the service and the facade and stitch it together to further decrease coupling.
    What's your opinion on passing a service object to the facade's __init__ function?
    I'd default it to =None and then create the service object in the body of the __init__. In testing, I'd explicitly pass some mock service to the __init__function.

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

    Perfect
    It's great if use material icon theme for vscode

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

    Thanks for the video. Here a bit of engagement for your work (I wonder if the algorithm factors comment_length into its weighting).

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

    Great video, I'm learning a lot from you. Thank you very much!
    It would be very cool if you make a video on 'How to use the Domain-Driven Design architecture with Django'.

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

      Thanks Yassine, Glad the content is useful.
      And Great suggestion thank you. I have put it in my list.

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

    Nice use of partial here. Any thoughts on managing a larger amount of controller functions with this approach?
    It seems like the benefit may taper off at some point, and would leave you reaching for classes.

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

    I admire you man! you are amazing

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

      Thank you, glad you liked the video!

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

    Thank you! 🙏

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

      You are so welcome Aashay, Glad the content is useful.

  • @NickLis-ob7fl
    @NickLis-ob7fl 2 года назад

    Arjan, tell about your vim config and vscode settings. pls

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

    I noticed that even in the facade, the power_speaker method creates the Connection and then immediately uses it. How would you test that? Where I work, we have a lot of code that looks like that - it creates a boto3 client and then immediately uses it. It's hell to test!

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

    0:37 I don't know if my sense of humor is broken, but I laughed more than I should've with this joke LOL

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

    I have a feeling that, using TDD, you would get to the Facade implementation without even thinking about it

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

    I love the suggestion, but like many of your refactoring videos, it put things into different parts of the code - it’s all logical, but probably confusing for people without the context that there has been a refactoring. Would it make sense to include in your video an effort to *document* the changes?
    I think having a short introduction to what the service does would be great - so many repos don’t have that, inexplicably, and an architectural overview too.

  • @АлексейБыков-и6ю
    @АлексейБыков-и6ю 2 года назад

    Controller in MVC isnt for business logic. Controller if for handling inputs and converting it for models or views. Business logic is a separate layer

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

    What's the difference between a facade and an adapter?

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

    Thanks for the video. But I have to be honest. halfway through the video I completely forgot what we were actually trying to achieve. I think you could explain all of these using a much simpler code example, in a much shorter video.

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

    Anybody know this IDE that Arjan is using?

  • @Naz-pk4ll
    @Naz-pk4ll 2 года назад +2

    haha you are a legend

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

      Thanks Naz, happy you’re enjoying the content!

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

    Is this how real world projects looks like?

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

    5:40 The only things evil about you are your horrific dad jokes 😂

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

      It’s only going to get worse, haha 😂

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

    Remember to use your overlord powers for good not evil :)

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

    Does anybody know the color theme he uses? Cant find any FAQ or something

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

      Isn't it standard VS Code? I have the same colors and didn't have to do anything special.

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

      @@rupen42 You're right! Thank you!

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

    @6:01 " * Well... kinda. There's no consensus on what MVC is exactly. I'll do a detailed video about that soon!" ....would that be, a much welcomed, part 2 of your previous MVC video? -- ruclips.net/video/ihtIcGkTFBU/видео.html -- looking forward to it!

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

      It's going to be a different example, but I'll talk about not only MVC but also varieties like MVP and MVVM.

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

    You are grat sir i like you 😍 🥰

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

      Thanks Dara, Glad that you liked the videos.

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

    The evil software development overlord on RUclips is now working on developing iot. What's next? A python module for your hobby Terminator project?

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

    You look like obi wan 😱

  • @MJ-xl5jz
    @MJ-xl5jz 2 года назад

    I wish you provided shorter and faster examples...

  • @Antonio-yc2kx
    @Antonio-yc2kx 2 года назад

    😏 p̲r̲o̲m̲o̲s̲m̲

  • @ayhamsaffar8407
    @ayhamsaffar8407 2 года назад +8

    PySimpleGUI >>>> TKinter