Search code examples
couplingcohesion

Cohesion VS. Coupling


This question will treat software like a tree, where:

  • Each node in the tree represents some code unit (eg class \ method \ line etc.)
  • Node X is son of Node Y if in the source code X is set in Y

Here is the definition of the term T:

T relative to Node X is the probability that any change on X will result changes in nodes that are within the sub-tree of X.

What is the term T? Cohesion or Coupling ?


Solution

  • Coupling would be horizontal, across nodes. Cohesion would be vertical, within the same tree. So T would be cohesion.

    Two separate modules, loosely coupled, would be in separate subtrees, and a change in one would not affect the other. But if tightly coupled, a change in one might require a change in the other, even though they are in separate subtrees. Obviously this cannot be what T is.