What is the difference between loose and tight coupling?
What does this picture have to do with coupling?
Well it was a tough choice between adding a coupler, a technical diagram explaining the programming concept (boring), or the cast of a hit British show called coupling. Forgive me: yes I do pander to the masses :P
tight coupling
Think of your skin. It’s stuck to your body. It fits like a glove. But what if you wanted to change your skin colour from say white to black? Can you imagine just how painful it would be to peel off your skin, dye it, and then to paste it back on etc? Changing your skin is difficult because it is tightly coupled to your body. You just can’t make changes easily. You would have to fundamentally redesign a human being in order to make this possible. In other words, if you want to change the skin, you would also HAVE TO change the design of your body as well because the two are joined together. God was not a good object oriented programmer.
loose coupling
Now think of getting dressed in the morning. You don’t like blue? No problems: you can put a red shirt on instead. You can do this easily and effortlessly because the shirt is not really connected to your body the same way as your skin. The shirt doesn’t know or care about what body it is going on. That is the key point. Clothes can easily and painlessly be changed. In other words, you can change your clothes, without really changing your body. That’s key point #2. If you change your shirt, then you are not forced to change your body. Whew! Perfect example of loose coupling.
Why is it important?
when refactoring code, you obviously don’t want to be forced to change 100 million things as a result of making just one change in your code. if you find yourself doing that, then more than likely: your code is tightly coupled. You want to change only ONE thing and have everything else just work as normal. that’s why loosely coupled code is important.
That’s the basic concept in a nutshell.
Now if you read the above explanations then you should have more of an idea of what is going on, and why it is important. Hope this helps.