Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coupling and cohesion

I'm trying to boil down the concepts of coupling and cohesion to a concise definition. Can someone give me a short and understandable explanation (shorter than the definitions on Wikipedia here and here)? How do they interact?

Thanks.

Anybody have a good, short example?

like image 926
Jonathan Avatar asked Sep 02 '08 16:09

Jonathan


People also ask

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.

What is high cohesion and low coupling?

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. In theory, the guideline looks pretty simple.

What is coupling and cohesion in software design?

Coupling refers to the interdependencies between modules, while cohesion describes how related the functions within a single module are. Low cohesion implies that a given module performs tasks which are not very related to each other and hence can create problems as the module becomes large.

What is coupling in a system?

Generically, coupling is a term we use to indicate how interdependent individual components of a system are. A tightly coupled system will be highly interdependent, where a loosely coupled system will have components that run independent from each other.


1 Answers

Coupling

  • Loose: You and the guy at the convenience store. You communicate through a well-defined protocol to achieve your respective goals - you pay money, he lets you walk out with the bag of Cheetos. Either one of you can be replaced without disrupting the system.

  • Tight: You and your wife.

Cohesion

  • Low: The convenience store. You go there for everything from gas to milk to ATM banking. Products and services have little in common, and the convenience of having them all in one place may not be enough to offset the resulting increase in cost and decrease in quality.

  • High: The cheese store. They sell cheese. Nothing else. Can't beat 'em when it comes to cheese though.

like image 57
Shog9 Avatar answered Oct 25 '22 18:10

Shog9