How To Reduce Coupling With Facade | Design Pattern Tutorial

44,063
22
Published 2022-11-18
The Facade design pattern is a great choice if you want to connect with a complex system via a simplified interface. In this tutorial, I show you how to apply the pattern to your own code and discuss some of the limitations of the pattern.

👉🏻 The code I worked on in this video is available here: github.com/ArjanCodes/2022-facade

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

💻 ArjanCodes Blog: www.arjancodes.com/blog

🎓 Courses:
The Software Designer Mindset: www.arjancodes.com/mindset
The Software Designer Mindset Team Packages: www.arjancodes.com/sas
The Software Architect Mindset: Pre-register now! www.arjancodes.com/architect
Next Level Python: Become a Python Expert: www.arjancodes.com/next-level-python
The 30-Day Design Challenge: www.arjancodes.com/30ddc

🛒 GEAR & RECOMMENDED BOOKS: kit.co/arjancodes.

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

💬 Discord: discord.arjan.codes/
🐦Twitter: twitter.com/arjancodes
🌍LinkedIn: www.linkedin.com/company/arjancodes
🕵Facebook: www.facebook.com/arjancodes
📱Instagram: www.instagram.com/arjancodes

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund

🎥 Video edited by Mark Bacskai: www.instagram.com/bacskaimark

🔖 Chapters:
0:00 Intro
0:51 Example explanation (IoT)
4:22 The facade pattern
5:47 Controller
12:25 Connecting to the GUI
16:14 Partial function applications
18:58 Facade pattern layer
26:03 Outro

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free con

All Comments (21)
  • @stonebam4611
    Your videos, especially on coupling, are really great! This series helped me so, so much beeing a better developer! Thank you very much!
  • @miQize
    Love the design patterns content!
  • @mamazu1995
    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.
  • @ChrisPatti
    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?
  • @edgeeffect
    Excellent, I've been throwing the word "Facade" around recently in my design for an Android App... This video popped up in my YouTube suggestions and I thought I'd better revisit it to make sure I'm not embarrassing myself. :)
  • @MRECoelho
    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!
  • @gurkhart
    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.
  • 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).
  • @FolkOverplay
    I would love to see another device to this code as a follow-up to see the more long-term benefits of this.
  • 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'.
  • 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.
  • @python6367
    Perfect It's great if use material icon theme for vscode
  • 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.
  • @beaulingpin
    Thanks for the video. Here a bit of engagement for your work (I wonder if the algorithm factors comment_length into its weighting).
  • 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.
  • @patrick1532
    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.