CSE Roadmap

Common tier · about 3 hours · 7 parts

Part 6 of 7 · 3 min read

Using the measures

The numbers point to places to look. They do not decide.

Using the measures

Think of a doctor's thermometer. A high reading means look closer. It does not name the illness.

A short method for a review of a code base:

  1. List the modules and count Ca and Ce from the call graph. Tools exist for most platforms.
  2. Compute I, A and D. Flag the modules with a high D, especially in the zone of pain.
  3. Look for low-cohesion modules: names like Utils, Helper, Common, or a high LCOM.
  4. For each flagged tie, name the connascence and its strength, locality and degree.
  5. Fix first the ties that are strong, far apart and have a high degree.

A worked example (made up). A web shop has a Common package used by all 20 modules. It holds date helpers, an email client, tax rules and a price formatter.

Check Finding
Ca 20
Ce 3
I 3 / 23, about 0.13
Abstractness Almost none
Cohesion Logical or coincidental
Verdict Zone of pain and low cohesion: any change touches 20 modules

A cure: split Common by purpose (dates, email, tax, pricing), and give each a small interface. Modules then depend only on the pieces they use.

This matters beyond tidiness. When a monolith is later split into services (page 8), a shared package like Common becomes shared code across services, and each service must carry its own copy or share a library. The book hints at this when it says that loose grouping hinders breaking a monolith apart.

Interview angle

Answer in your head first, then open it.

What is the difference between coupling and cohesion?

Coupling is the ties between modules. Cohesion is how well the parts inside one module belong together. Aim for low coupling and high cohesion.

What is afferent and efferent coupling?

Incoming and outgoing dependencies.

What is connascence?

Two parts that must change together. Prefer weak, static, local and low-degree forms.

How would you find a risky module?

High Ca with low abstractness (zone of pain), or low cohesion with a vague name.

Are metrics enough?

No. They need interpretation, and why a grouping exists matters more.

Check yourself:

  • Which module would you fix first: strong connascence within one class, or weak connascence across 30 services?
  • Name one risk of trusting a single metric.

Words you will meet

Word Plain meaning
Module A named group of related code
Component A larger building block, often a module with a clear job
Cohesion How well the parts of a module belong together
LCOM A count of how little the methods in a class share fields
Coupling Ties between modules
Afferent coupling (Ca) Incoming dependencies
Efferent coupling (Ce) Outgoing dependencies
Instability (I) Ce divided by (Ce plus Ca)
Abstractness (A) Abstract elements divided by concrete ones
Main sequence The ideal line A + I = 1
Zone of pain Concrete, stable code that many rely on
Zone of uselessness Abstract, unstable code nobody uses
Connascence A tie where change in one forces change in the other
Static, dynamic connascence Visible in source code, or only at run time