How To Reduce Coupling With Facade | Design Pattern Tutorial

  Рет қаралды 43,927

ArjanCodes

ArjanCodes

Күн бұрын

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-fa...
👷 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...
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: / arjancodes
🌍LinkedIn: / arjancodes
🕵Facebook: / arjancodes
📱Instagram: / arjancodes
👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund
🎥 Video edited by Mark Bacskai: / 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 content each week!

Пікірлер: 62
@ArjanCodes
@ArjanCodes 9 ай бұрын
👷 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 Жыл бұрын
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 Жыл бұрын
Thanks so much, glad the content is helpful!
@edgeeffect
@edgeeffect 9 ай бұрын
Excellent, I've been throwing the word "Facade" around recently in my design for an Android App... This video popped up in my KZfaq suggestions and I thought I'd better revisit it to make sure I'm not embarrassing myself. :)
@miQize
@miQize Жыл бұрын
Love the design patterns content!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks Mikko, Glad you like them!
@mamazu1995
@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.
@aflous
@aflous Жыл бұрын
Yep, I was expecting to see protocol at some point as well
@thisoldproperty
@thisoldproperty Жыл бұрын
I wasn’t aware of the partial function. Nice one!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad the content is helpful!
@ChrisPatti
@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?
@mrsystem9560
@mrsystem9560 Жыл бұрын
I admire you man! you are amazing
@ArjanCodes
@ArjanCodes Жыл бұрын
Thank you, glad you liked the video!
@MRECoelho
@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!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks M. Coelho, happy you’re enjoying the content!
@aashayamballi
@aashayamballi Жыл бұрын
Thank you! 🙏
@ArjanCodes
@ArjanCodes Жыл бұрын
You are so welcome Aashay, Glad the content is useful.
@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.
@python6367
@python6367 Жыл бұрын
Perfect It's great if use material icon theme for vscode
@fredesch3158
@fredesch3158 Жыл бұрын
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
@gurkhart
@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.
@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.
@doluparsad6379
@doluparsad6379 Жыл бұрын
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).
@blazpotokar8159
@blazpotokar8159 Жыл бұрын
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.
@yassinemahtat9373
@yassinemahtat9373 Жыл бұрын
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 Жыл бұрын
Thanks Yassine, Glad the content is useful. And Great suggestion thank you. I have put it in my list.
@beaulingpin
@beaulingpin Жыл бұрын
Thanks for the video. Here a bit of engagement for your work (I wonder if the algorithm factors comment_length into its weighting).
@ivanherreros7773
@ivanherreros7773 Жыл бұрын
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.
@NickLis-ob7fl
@NickLis-ob7fl Жыл бұрын
Arjan, tell about your vim config and vscode settings. pls
@patrick1532
@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.
@ArjanCodes
@ArjanCodes Жыл бұрын
Haha, always love that when it happens :).
@nalinor
@nalinor Жыл бұрын
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.
@danny_p466
@danny_p466 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@ego_rod Yeah figured this out in the meantime, I was writing the comments while I was watching the video :D
@billfujimoto5905
@billfujimoto5905 Жыл бұрын
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.
@YossiZinger
@YossiZinger Жыл бұрын
I have a feeling that, using TDD, you would get to the Facade implementation without even thinking about it
@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!
@Naz-pk4ll
@Naz-pk4ll Жыл бұрын
haha you are a legend
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks Naz, happy you’re enjoying the content!
@tehdusto
@tehdusto Жыл бұрын
Anybody know this IDE that Arjan is using?
@mikeciul8599
@mikeciul8599 Жыл бұрын
What's the difference between a facade and an adapter?
@user-rr6zh2iw8h
@user-rr6zh2iw8h Жыл бұрын
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
@bertilhatt
@bertilhatt Жыл бұрын
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.
@darasingh503
@darasingh503 Жыл бұрын
You are grat sir i like you 😍 🥰
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks Dara, Glad that you liked the videos.
@tahashakibania3061
@tahashakibania3061 Жыл бұрын
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.
@OleZZ222
@OleZZ222 Жыл бұрын
Does anybody know the color theme he uses? Cant find any FAQ or something
@rupen42
@rupen42 Жыл бұрын
Isn't it standard VS Code? I have the same colors and didn't have to do anything special.
@OleZZ222
@OleZZ222 Жыл бұрын
@@rupen42 You're right! Thank you!
@julluj5624
@julluj5624 Жыл бұрын
Is this how real world projects looks like?
@zacharythatcher7328
@zacharythatcher7328 Жыл бұрын
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.
@tthompson5707
@tthompson5707 Жыл бұрын
Remember to use your overlord powers for good not evil :)
@djl3009
@djl3009 Жыл бұрын
@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? -- kzfaq.info/get/bejne/n86kfMZ40Lqqcok.html -- looking forward to it!
@ArjanCodes
@ArjanCodes Жыл бұрын
It's going to be a different example, but I'll talk about not only MVC but also varieties like MVP and MVVM.
@frogstud
@frogstud Жыл бұрын
You look like obi wan 😱
@MorselHoarder
@MorselHoarder Жыл бұрын
5:40 The only things evil about you are your horrific dad jokes 😂
@ArjanCodes
@ArjanCodes Жыл бұрын
It’s only going to get worse, haha 😂
@alexandarjelenic2880
@alexandarjelenic2880 Жыл бұрын
The evil software development overlord on KZfaq is now working on developing iot. What's next? A python module for your hobby Terminator project?
@MJ-xl5jz
@MJ-xl5jz Жыл бұрын
I wish you provided shorter and faster examples...
@Antonio-yc2kx
@Antonio-yc2kx Жыл бұрын
😏 p̲r̲o̲m̲o̲s̲m̲
@ayhamsaffar8407
@ayhamsaffar8407 Жыл бұрын
PySimpleGUI >>>> TKinter
Which Software Architecture Should You Use: MVC, MVP, or MVVM?
24:27
How to Avoid Refactoring Legacy Code HELL
35:57
ArjanCodes
Рет қаралды 35 М.
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 45 МЛН
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 137 МЛН
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 41 МЛН
Haha😂 Power💪 #trending #funny #viral #shorts
00:18
Reaction Station TV
Рет қаралды 16 МЛН
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 274 М.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 202 М.
GRASP Design Principles: Why They Matter (And How to Use Them)
32:02
Let's Take The Adapter Design Pattern To The Next Level
22:45
ArjanCodes
Рет қаралды 49 М.
Click: Build Your Own Command Line Interface Tool
25:12
ArjanCodes
Рет қаралды 15 М.
Variations of the Strategy Pattern // Using Python Features!
27:20
The Ultimate Guide to Writing Functions
24:31
ArjanCodes
Рет қаралды 178 М.
A Deep Dive Into Iterators and Itertools in Python
21:01
ArjanCodes
Рет қаралды 59 М.
10 Design Patterns Explained in 10 Minutes
11:04
Fireship
Рет қаралды 2,2 МЛН
Why Use Design Patterns When Python Has Functions?
23:23
ArjanCodes
Рет қаралды 100 М.
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 45 МЛН