BolEnglishLearn · Play · Win
Login

🧲 Software Design Principles · Core Principles

🧲

High Cohesion

Design PrincipleIntermediateModule 2

Related responsibilities belong together.

A module is easier to understand when its contents serve one purpose.

💡 In practice

All invoice calculation rules live in the Billing module.

🖼️ CONCEPT PICTURE
A picture to help remember High Cohesion
All invoice calculation rules live in the Billing module.

💡 Like a well-organized toolbox: all the screwdrivers in one tray, so you always know where to reach.

💡 Learn🛠️ Apply🎯 Check

💡 Why it matters

When related code lives together, you can find it, understand it and change it in one place. Low cohesion scatters a single idea across the codebase, so every change becomes a hunt. High cohesion makes modules self-explanatory and pairs naturally with loose coupling to keep a system tidy.

🛠️ How to achieve it

1
Group by purpose
Keep all the code that serves one goal, like billing, together in one module.
2
Give the module one job
If a module covers several unrelated ideas, split it so each has a single clear purpose.
3
Keep helpers close
Put small helper code next to the feature it supports, not in a distant catch-all file.
4
Name by what it holds
Name the module after its purpose so its contents are predictable.

⚠️ Signs of trouble

  • •One feature's logic is scattered across many modules.
  • •A module mixes several unrelated ideas.
  • •You must jump between files to follow one simple change.
  • •Catch-all files like Common or Misc keep growing.
⚠️ Common mistake: Dumping unrelated helpers into a shared "Common" bucket. Group code by the purpose it serves so each module has one clear job.

🎯 Quick check

Score: 0/3

Three questions to test the idea.

  1. 1. What does high cohesion mean for a module?

    Answer: Its parts all serve one clear purpose

    A cohesive module groups related responsibilities so it is easy to find and understand.

  2. 2. Where should all invoice calculation rules live?

    Answer: Together in the Billing module

    Keeping related billing rules in one module makes them easy to find and change together.

  3. 3. What is a sign of low cohesion?

    Answer: One feature's logic scattered across many modules

    Scattered logic for a single idea is the classic symptom of low cohesion.

🔑 Key terms

Cohesion
How strongly the parts of a module belong together.
Module
A grouped unit of related code.
Low cohesion
A module whose parts have little to do with each other.
Catch-all
A grab-bag file holding unrelated odds and ends.

✅ Review checklist

📊 Your progress

0%
Mark this topic learned to track it.
Saved in this browser.
🚀 Got it?
Mark it learned and move to the next topic.
Next topic →