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.

--

--

--

Software developer and occasional blogger: https://blog.ttulka.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Does Freshdesk Azure DevOps Integration supports TFS?

Setting up secure Pub/Sub flow with Go and Terraform

How to Fix Terraform Codes When Infrastructure is Changed from AWS Console

SAML for SaaS Engineers

Optimize Website Speed with Varnish Cache

Future of code to be launched in 2021-Mobile App Developers are you listening?

Darwinia Highlight September | Monthly Recap

Top 5 Web Development to Shape 2022 and Beyond

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
Tomas Tulka

Tomas Tulka

Software developer and occasional blogger: https://blog.ttulka.com

More from Medium

The Layered Architecture Pattern in Software Architecture

Understanding Software Cohesion & Coupling

Legacy software series — Part 3 — Modernizing legacy software

Write less but clean quality code.