Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cohesion and Decoupling, what do they represent?

What are Cohesion and Decoupling? I found information about coupling but not about decoupling.

like image 224
dbtek Avatar asked May 21 '10 11:05

dbtek


People also ask

What is meant by cohesion and coupling?

" Coupling " describes the relationships between modules, and " cohesion " describes the relationships within them. A reduction in interconnectedness between modules (or classes) is therefore achieved via a reduction in coupling.

What does decoupling mean in programming?

In computing, the term decoupled architecture describes a processor in a computer program that uses a buffer to separate the fetch and decode stages from the execution stage.

What does high cohesion and low coupling means?

2. High cohesion, low coupling guideline. In essence, high cohesion means keeping parts of a code base that are related to each other in a single place. Low coupling, at the same time, is about separating unrelated parts of the code base as much as possible.

What is cohesion and coupling explain with example?

Coupling shows the relationships between modules. Cohesion shows the relationship within the module. Coupling shows the relative independence between the modules. Cohesion shows the module's relative functional strength. While creating, you should aim for low coupling, i.e., dependency among modules should be less.


1 Answers

That article from Aaron is very good for understanding, also I'd recommend that you read manning publications 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.

like image 128
ant Avatar answered Oct 16 '22 02:10

ant