How Cohesion And Coupling Correlate

In the rain (cut) by Franz Marc

What is cohesion, anyway?

The cohesion formula
Examples of cohesion measurement
Example measurements of cohesion

Myth busted

Cohesion and coupling

Low cohesion, tight coupling
Low cohesion, tight coupling
High cohesion, tight coupling
High cohesion, tight coupling
High cohesion, loose coupling
High cohesion, loose coupling

Focus on cohesion, not coupling

Level of abstraction

“The whole is greater than the sum of the parts.” ~ Aristotle

Coupling on the higher level of abstraction is dramatically reduced
Coupling on the higher level of abstraction is dramatically reduced

Talk to me in code!

class BookStore {
add(book) { … }
remove(book) { … }
sale(book) { … }
receiptFor(book) { … }
}
class Inventory {
add(book) { … }
remove(book) { … }
}

class Sales {
sale(book) { … }
receiptFor(book) { … }
}
class Sales {
sale(book) { … }
}

class Accounting {
receiptFor(book) { … }
}

Conclusion

  • Coupling is about connections, cohesion is about belonging together.
  • Cohesion cannot be created automatically; instead it is discovered in a context.
  • Cohesion is defined by the clients.
  • True cohesion is domain-driven.
  • High cohesion results in loose coupling.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store