Skip to content
BENIBIX Learn

Cohesion

Development🏗️ ArchitectureArchitecture Basics

Also known as High Cohesion, Low Cohesion

How well the code in one part fits together.

Think of it like

Think of it like a toolbox that only holds tools. You never find socks in it.

Example

Lucy's utils file holds date code, email code and price maths. She splits it into three files. Each one now has a clear name and purpose.

Why it matters

When code that belongs together sits together, a change happens in one place. You do not hunt for it.

Definition

Cohesion is how well the code in one part of a program fits together. High cohesion means every function in a module serves the same purpose. Low cohesion means a module is a grab bag of unrelated jobs. High cohesion makes code easy to find and easy to name. It goes with loose coupling. Parts that do one thing need each other less.

Common mistake

Making a file called helpers or utils and putting all sorts in it. It soon gets the hardest file to change.

Key takeaways

  1. 1
    One purpose. Per module.
  2. 2
    Easy to name. A sign it is focused.
  3. 3
    Pairs with loose coupling. Two sides of one goal.

Compare