views:

125

answers:

3

Can anyone tell me what are Cohesion and Decoupling? I found coupling but there is no Decoupling anywhere. I need to learn their meanings.

Any help will be appreciated. Thanks for replying.

+1  A: 

For coupling, this Wikipedia article should answer all your questions. This article deals with cohesion.

"Decoupling" is just another name for "little/low coupling".

So these terms answer these questions:

  • How much does each part of your project depend on another part?
  • If you wanted to use just a part of your project (like to solve a specific problem) how much do you need to know about all the rest of the project?
  • Is every part of your project focused on a single solution to a specific problem or do solutions "leak" to other parts?
Aaron Digulla
decoupling refers to making a tightly coupled section, more loosely coupled - or not coupled at all. Coupling/cohesion are certainly not the same principle, but they have the common aim of making a system more flexible.
Robert
What did you mean by 'all these terms mean the same thing' ? I am not sure if I follow you on that one. As Robert pointed out, they indeed mean different things
Shravan
Thanks, I've improved my answer.
Aaron Digulla
Thanks for help.
dbtek
+3  A: 

That article from Aaron is very good for understanding, also I'd recommend that you read maning Spring in Action book, they give very good examples on how the spring solves that problem it will definitely improve your understanding of this.

EDIT :

I came accross this in this great book called Growing object oriented software guided by tests :

Coupling :

Elements are coupled if a change in one forces a change in the other. For example, if two classes inherit from a common parent, then a change in one class might require a change in the other. Think of a combo audio system: It’s tightly coupled because if we want to change from analog to digital radio, we must rebuild the whole system. If we assemble a system from separates, it would have low coupling and we could just swap out the receiver. “Loosely” coupled features (i.e., those with low coupling) are easier to maintain.

Cohesion:

An element’s cohesion is a measure of whether its responsibilities form a meaningful unit. For example, a class that parses both dates and URLs is not coherent, because they’re unrelated concepts. Think of a machine that washes both clothes and dishes—it’s unlikely to do both well.2 At the other extreme, a class that parses only the punctuation in a URL is unlikely to be coherent, because it doesn’t represent a whole concept. To get anything done, the programmer will have to find other parsers for protocol, host, resource, and so on. Features with “high” coherence are easier to maintain.

c0mrade
+4  A: 

Cohesion - related to the principle that a class/method should be responsible for one thing only i.e there are no stray methods that don't belong in the encapsulation; a method only does one thing. High/Low cohesion is the degree to which this holds.

Coupling - how interdependent different parts of the system are. e.g how and where there are dependencies. If two classes make calls to methods of each other then they are tightly coupled, as changing one would mean having to change the other. Decoupling is the process of making something that was tightly coupled less so, or not at all.

Flexible systems have High Cohesion and Loose Coupling.

Robert