Enter your Email Address:

Delivered by FeedBurner

To get posts delivered to your Email

26 January 2011

Why Loose Coupling is Strong Coupling?

Often, senior programmers insist us to have a loose coupling. In order to appreciate those words - "go for loose coupling", we need to understand what does it mean by loose coupling.

There is another good practice encouraged by senior developers which is modularity. Often, they want us to write function or methods which is just a screen's length (by the way for 14 inch monitor :-)). How can loose coupling be possible when you have modularity? When your application is highly modularized, you heavily depends on many modules to accomplish things.

The concept of modularity in fact leads to loose coupling. By modularity, we make a part of the code to do one critical thing. We don't want any part (or technically a unit) of the code to do two things. We want to restrict to a critical thing and by modularity we also want to hide the gory details underneath. When modularity is practiced in a structural programming, we tend to get loose coupling in a structural language/programming and when we follow right abstraction in object oriented paradigm, we get right loose coupling in object orientation. The modularity mean do one thing that is appropriate to the level of abstraction.

The loose coupling is not restricted to a specific programming types but rather has to be seen as a concept. The application of concept can be different in different programming language types like modularity, abstraction (having hierarchies of abstraction, each level of abstraction marries to a same level of abstraction to realize the functionality).

So, loose coupling helps us to realize strong coupling between objects but avoids tight coupling (which is a code smell).

What do you think?

2 comments:

Kris said...

If loose coupling boosts strong coupling, why name it so?

Lakshmi Narayanan N said...

@Kris
I m not sure whether i got your question right. but i go ahead and answer.

In design, when we encapsulate, allow modularity and most importantly tie-up same levels of abstraction, it gives us loose coupling. The loose coupling actually gives strength to the design as it offers lot of flexibility during later stage - software maintenance.

The opposite to above points discussed is called "tight coupling". Tight coupling gives weakness to design.