Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

jon kelson
5,149 Pointswhat is meant by tight coupling and why should we avoid it ?
what is meant by tight coupling and why should we avoid it ?
2 Answers

Oliver Duncan
16,642 PointsTight coupling is when two or more aspects of your program depend on each other too much. Here's an article on the subject: https://en.m.wikipedia.org/wiki/Coupling_(computer_programming)
As developers we want to keep all of our code decoupled so that when a change must be made to a part of our program, we only have to change the part that needs it, and not the whole program.
Imagine you had an app that did three different things, but responsibility for each was spread out among all your view controllers and data models. If one of those things your app did stopped working, it would take a lot of time to hunt down and fix the bug. If however you had kept your code decoupled, you would just need to find the part of your code that was responsible for the task that's buggy, and fix it.
In other words, all the functions and classes in your code should be tightly focused on doing one thing, and that's it. They shouldn't know about what goes on inside any other class.
Hope that explains it a little, I'm still trying to wrap my head around it myself.

jon kelson
5,149 Pointsthank you very much Oliver and Steven great answers , now I understand !
Steven Deutsch
21,046 PointsSteven Deutsch
21,046 PointsIt sound's like you have an excellent understanding of this topic Oliver Duncan and provided a great explanation. Allow me to add to what you have touched on already. When writing good code we strive to follow the single responsibility principle.
This means that your classes and methods should be focused on a single task, the smallest piece of functionality, and as separated as possible. This not only help's with code interchangeability and the debugging process, but also leads to great code reuse and data encapsulation.
By keeping your code loosely coupled you limit the interaction your program can have with certain parts of the data. You only allow it access to the bare necessities it needs to function.
Loosely coupled code is also highly reusable. By writing more modularized code you will very easily be able to reuse this code on other projects or even in the same projects (sometimes it's even as easy as copy and pasting). Whereas with tightly coupled code, you would have to unknot it from your application and then modify it to fit your needs.
Oliver Duncan
16,642 PointsOliver Duncan
16,642 PointsThank you, Steven. Your reply is extremely articulate and right on the money.