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.
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. :)
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.
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).
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.
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.
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.
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!
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.
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.
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.
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?
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.
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.
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'.
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.
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!
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.
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.
@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!
👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis
Your videos, especially on coupling, are really great! This series helped me so, so much beeing a better developer! Thank you very much!
Thanks so much, glad the content is helpful!
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.
Yep, I was expecting to see protocol at some point as well
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. :)
I would love to see another device to this code as a follow-up to see the more long-term benefits of this.
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.
I wasn’t aware of the partial function. Nice one!
Thanks so much, glad the content is helpful!
Love the design patterns content!
Thanks Mikko, Glad you like them!
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).
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.
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.
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.
@@ego_rod Yeah figured this out in the meantime, I was writing the comments while I was watching the video :D
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!
Thanks M. Coelho, happy you’re enjoying the content!
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.
Haha, always love that when it happens :).
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.
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.
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?
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.
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.
Perfect
It's great if use material icon theme for vscode
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, 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'.
Thanks Yassine, Glad the content is useful.
And Great suggestion thank you. I have put it in my list.
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.
I admire you man! you are amazing
Thank you, glad you liked the video!
Thank you! 🙏
You are so welcome Aashay, Glad the content is useful.
Arjan, tell about your vim config and vscode settings. pls
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!
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
I have a feeling that, using TDD, you would get to the Facade implementation without even thinking about it
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.
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
What's the difference between a facade and an adapter?
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.
Anybody know this IDE that Arjan is using?
haha you are a legend
Thanks Naz, happy you’re enjoying the content!
Is this how real world projects looks like?
5:40 The only things evil about you are your horrific dad jokes 😂
It’s only going to get worse, haha 😂
Remember to use your overlord powers for good not evil :)
Does anybody know the color theme he uses? Cant find any FAQ or something
Isn't it standard VS Code? I have the same colors and didn't have to do anything special.
@@rupen42 You're right! Thank you!
@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!
It's going to be a different example, but I'll talk about not only MVC but also varieties like MVP and MVVM.
You are grat sir i like you 😍 🥰
Thanks Dara, Glad that you liked the videos.
The evil software development overlord on RUclips is now working on developing iot. What's next? A python module for your hobby Terminator project?
You look like obi wan 😱
I wish you provided shorter and faster examples...
😏 p̲r̲o̲m̲o̲s̲m̲
PySimpleGUI >>>> TKinter