Cohesion and Coupling: Write BETTER PYTHON CODE Part 1

214,174
0
Published 2021-01-22
Writing code, especially in larger software projects can be very challenging. In this video, I'm going to cover cohesion and coupling to help you write better code. I'll go through a Python program in detail and I'll show you how to write code that has low coupling and strong cohesion. Coupling and Cohesion are part of the GRASP principles of object-oriented design, as proposed by Craig Larman in his book (see below for a link).

Here are a few books about software design that might interest you:
- Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, by Craig Larman: amzn.to/364wgLb
- Design Patterns: Elements of Reusable Object-Oriented Software, by the Gang of Four: amzn.to/39451Cv

💡Here's my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.

🎓 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.

You can find the code I worked on in this episode in my GitHub repository: github.com/arjancodes/betterpython

All parts in this series:
Part 1: Cohesion and coupling -    • Cohesion and Coupling: Write BETTER P...  
Part 2: Dependency inversion -    • Dependency Inversion: Write BETTER PY...  
Part 3: The strategy pattern -    • The Strategy Pattern: Write BETTER PY...  
Part 4: The observer pattern -    • Observer Pattern Tutorial: I NEVER Kn...  
Part 5: Unit testing and code coverage -    • 100% CODE COVERAGE - Think You're Don...  
Part 6: Template method and bridge -    • Two UNDERRATED Design Patterns 💡 Writ...  
Part 7: Exception handling -    • Exception Handling Tips in Python ⚠ W...  
Part 7b: Monadic error handling -    • Monadic Error Handling in Python ⚠ Wr...  
Part 8: Software architecture -    • Why You Should Think About SOFTWARE A...  
Part 9: SOLID principles -    • Uncle Bob’s SOLID Principles Made Eas...  
Part 10: Object creation patterns -    • QUESTIONABLE Object Creation Patterns...  

Chapters:
0:00 Introduction
0:47 What is cohesion?
1:37 What is coupling?
3:59 Code example intro
6:39 Analyzing the code
7:56 Information expert
11:19 Reducing coupling
16:32 Improving cohesion
22:40 Recap
25:37 Outro

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!

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 w

All Comments (21)
  • @kannankalidasan
    Believe me. There are no videos on youtube other than you to my knowledge that explain the design pattern before and after effect with real practice examples . Thank you so much !
  • @DaviSilveira
    Thank you for not making 'hello world' tutorials!!!!!!! Keep going! :)
  • @ShanilPanara
    Honestly, this is some of, if not the best, intermediate/advanced level content out there! Too many people focussing on the pure basics, but you presented this in such an easy to understand way! Forget binging Netflix, time to binge Arjan 😂 Thanks a lot ❤️
  • @mrdupreez9061
    This is exactly the sort of level of information I need at my stage of learning to code. thank you so much really appreciate the thought you've put into this!
  • @talhaamir9023
    Highly Underrated Video, should have more than a million views. There are very important concepts which programmers don't even know. Thanks for the High Quality Content !!
  • @Dgrayfit
    I absolutely love this channel. I have always really struggled with the idea of trying to identify what "intermediate" level coding is, and I would say this channel really fills that gap in the existing YouTube literature for python coding. I think this channel is going to really level up my skills, can't wait to see more!
  • @5thbatman
    It is not even possible to get this kind information from paid sources, but you are great person that making these kind of valuable lessons available on youtube. Thank you very much for all the effort, Respect.
  • @Ben-kz2km
    Great video. I'm a data scientist but moving more and more to software development. I'm still having a hard time writing good code, but I'm starting to be able to recognize it when I see it. Videos like this are super helpful with that.
  • Fantastic series! I think all of the concepts you're discussing are vastly under-appreciated
  • @olegpopov3180
    I noticed cohesion and coupling are pretty similar to the concept of between and within dispersion in cluster analysis. Kinda cluster should be maximized by between-cluster distance and minimize by within distance of elements inside. Why I noticed this only after your video? Your explanations are really genious.
  • @thesupercoach
    Love your work man. Your calm and clear delivery is a breath of fresh air. Keep it up.
  • @pimdubuf3272
    This series is great, both the topics and your way of explaining stuff. Thanks for taking the time to make these!
  • @robertchang5096
    Your videos are absolutely amazing! I can only imagine how much work and hours you have put into this. Thank you for sharing your knowledge to all of us learning Python!
  • @mrdbourke
    Absolutely outstanding video Arjan! I've been coding Python for ~5 years and always saw these techniques in play but never really knew where they were coming from. Looking forward to the rest of the series.
  • @ahmedlv5499
    Your videos have changed the way I code. This is my second time going through this playlist. Since watching your videos I have been writing better code. Trying to do better every time. I have even done better at interviews. Thank you so much for great content. Merry Christmas and Happy New Year!
  • This is a such a great series! I've been looking for intermediate level design content for years. You've nailed the delivery and content. Looking forward to seeing more videos.
  • @nijataliyev1470
    Holy cow, this is first video that I am subscribing, liking and sharing right away. This is a gem. Thank you very much Arjan.
  • I was so frustrated of going through tonnes of leetcode interview exercises/tutorials and was looking for a more philosophical understanding of how to design python codes. Then I found your channel, I am now more confident after going through some if not all of your videos. Keep it up! The coding challenge is soon, will update if your content helped me land the job.
  • Great stuff, thank you!! I really appreciate this kind of intermediate+ material. There is very little available. Looking forward to the rest of the series.