Skip to content

Divergent Change: One Module, Many Unrelated Reasons to Change

How to spot a class that keeps changing for unrelated reasons, why it slows teams down, and how to split it along its axes of change.

6 min readCode smellRigidity

Divergent change is when one module keeps getting edited for reasons that have nothing to do with each other. On Monday you touch it because finance changed a fee rule. On Wednesday you touch it again because the data team wants a different CSV separator. On Friday it changes once more because support rewrote an email. Each edit is small, but every one lands in the same file. The edits collide in code review, they risk breaking each other, and anyone who opens the file has to understand all of its concerns just to change one. The fix is to find the separate axes of change and give each one its own home.

Signs

How to spot it in a review.

  • The commit history for one file reads like a list of unrelated tickets: pricing, export format, notification copy, logging.
  • You can group the methods by which team or stakeholder asks for changes to them, and the groups barely call each other.
  • A change to one concern forces you to rerun or rewrite tests for concerns you never touched.
  • Merge conflicts in the file come from people working on unrelated features.
  • Describing the class honestly needs the word "and" several times: it calculates payouts and exports reports and writes emails.

What it looks like

A typical case, in three languages.

type Tier = "standard" | "pro";

interface Payout {
  freelancerId: string;
  country: string;
  tier: Tier;
  grossCents: number;
}

const FEE_BPS: Record<Tier, number> = { standard: 1200, pro: 800 };
const WITHHOLDING_BPS: Record<string, number> = { US: 0, GB: 2000, IN: 1000 };
const DEFAULT_WITHHOLDING_BPS = 3000;

function money(cents: number): string {
  return (cents / 100).toFixed(2);
}

export class PayoutStatement {
  constructor(private readonly payouts: Payout[]) {}

  // Finance asks for changes here: fee tiers, withholding rules.
  netCents(p: Payout): number {
    const fee = Math.floor((p.grossCents * FEE_BPS[p.tier]) / 10000);
    const rate = WITHHOLDING_BPS[p.country] ?? DEFAULT_WITHHOLDING_BPS;
    const withholding = Math.floor(((p.grossCents - fee) * rate) / 10000);
    return p.grossCents - fee - withholding;
  }

  // The data team asks for changes here: columns, separators, decimals.
  toCsv(): string {
    const header = "freelancer_id;country;gross;net";
    const rows = this.payouts.map((p) =>
      [p.freelancerId, p.country, money(p.grossCents), money(this.netCents(p))].join(";"),
    );
    return [header, ...rows].join("\n");
  }

  // Support asks for changes here: wording, tone, sign-off.
  emailBody(p: Payout): string {
    return [
      `Hi ${p.freelancerId},`,
      "",
      `Your payout of $${money(this.netCents(p))} is on its way.`,
      `Fee tier: ${p.tier}.`,
      "",
      "The Gigloom team",
    ].join("\n");
  }
}

Gigloom, a freelance marketplace, pays out weekly. PayoutStatement looks cohesive because every method deals with payouts, but three different groups own its three methods. Finance changes the fee and withholding rules, the data team changes the CSV layout, and support rewrites the email. A ticket to switch the CSV to commas sits in the same file, and the same test suite, as a ticket to add a new fee tier. The only real link between the concerns is that the export and the email both need netCents, so that calculation is the seam to split along.

Why it happens

How code ends up like this.

  • A class gets named after a domain noun, such as Payout, Order or Invoice, and every feature that mentions that noun ends up inside it.
  • Calculation, formatting and delivery start out tiny, so putting them together feels harmless. They only diverge once each one picks up its own stakeholder.
  • Adding a method to an existing class is the path of least resistance, while creating a new module feels like a design decision that needs justifying.
  • The team never asked which parts change together and which change independently, so the boundaries follow the data instead of the reasons for change.

Treatment

The refactorings that cure it, and when to choose each.

Payoff

What you get once it's gone.

  • Each change request touches one small module, so diffs stay focused and reviews are faster.
  • Tests line up with concerns: changing the CSV separator no longer reruns or breaks fee calculation tests.
  • Different teams can work in parallel without merge conflicts in one shared file.
  • The calculator can be reused elsewhere, for example in an invoice preview, without dragging export and email code along.

When to leave it

Sometimes it's not worth fixing.

  • The module is young and its concerns have changed together so far. Wait until you see at least two independent change histories before you split.
  • The class is small enough that the whole thing fits on one screen and nobody struggles to change it. Splitting a 40-line file into three can add more navigation cost than it saves.
  • The concerns really do change together, for example a format that is defined by the same external spec as the calculation. In that case they belong to one axis of change.

Common questions

Short answers to the usual doubts.

How is divergent change different from shotgun surgery?

They are mirror images. Divergent change is one module changing for many different reasons. Shotgun surgery is one reason forcing you to change many modules. The first calls for splitting a module apart. The second calls for pulling scattered code together.

Isn't this just the Single Responsibility Principle?

It is closely related. SRP is the design goal: a module should have one reason to change. Divergent change is the symptom you observe when that goal is violated, usually by reading the commit history or noticing which stakeholders request edits to a file.

How do I find the axes of change in a real codebase?

Look at the file's commit log and group the commits by ticket or by who requested them. Then check which methods each group touched. Methods that always change together form one axis. Methods that change on their own schedule are candidates to extract.

What should I say if an interviewer shows me a class like this?

Name the smell, then list the distinct reasons the class would change and who would request each one. Propose splitting along those lines, point out the shared dependency, here the net calculation, as the seam, and mention that you would do the split in small steps behind passing tests. Also say when you would leave it alone, because that shows judgement rather than rule-following.

Does splitting the class change the program's behaviour?

It should not. Extract Class and Move Function are behaviour-preserving refactorings. Keep the existing tests green after each step, and if the original class has public callers, keep it as a thin wrapper that delegates to the new classes until those callers are migrated.

Next guide2 of 3 · Smells: rigidityShotgun Surgery: When One Change Means Edits in Many FilesRead the next one