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");
}
}from dataclasses import dataclass
FEE_BPS = {"standard": 1200, "pro": 800}
WITHHOLDING_BPS = {"US": 0, "GB": 2000, "IN": 1000}
DEFAULT_WITHHOLDING_BPS = 3000
@dataclass(frozen=True)
class Payout:
freelancer_id: str
country: str
tier: str
gross_cents: int
def money(cents: int) -> str:
return f"{cents / 100:.2f}"
class PayoutStatement:
def __init__(self, payouts: list[Payout]) -> None:
self.payouts = payouts
# Finance asks for changes here: fee tiers, withholding rules.
def net_cents(self, p: Payout) -> int:
fee = p.gross_cents * FEE_BPS[p.tier] // 10000
rate = WITHHOLDING_BPS.get(p.country, DEFAULT_WITHHOLDING_BPS)
withholding = (p.gross_cents - fee) * rate // 10000
return p.gross_cents - fee - withholding
# The data team asks for changes here: columns, separators, decimals.
def to_csv(self) -> str:
header = "freelancer_id;country;gross;net"
rows = [
";".join([p.freelancer_id, p.country, money(p.gross_cents), money(self.net_cents(p))])
for p in self.payouts
]
return "\n".join([header, *rows])
# Support asks for changes here: wording, tone, sign-off.
def email_body(self, p: Payout) -> str:
return "\n".join([
f"Hi {p.freelancer_id},",
"",
f"Your payout of ${money(self.net_cents(p))} is on its way.",
f"Fee tier: {p.tier}.",
"",
"The Gigloom team",
])<?php
declare(strict_types=1);
const FEE_BPS = ['standard' => 1200, 'pro' => 800];
const WITHHOLDING_BPS = ['US' => 0, 'GB' => 2000, 'IN' => 1000];
const DEFAULT_WITHHOLDING_BPS = 3000;
final class Payout
{
public function __construct(
public readonly string $freelancerId,
public readonly string $country,
public readonly string $tier,
public readonly int $grossCents,
) {}
}
function money(int $cents): string
{
return number_format($cents / 100, 2, '.', '');
}
final class PayoutStatement
{
/** @param Payout[] $payouts */
public function __construct(private array $payouts) {}
// Finance asks for changes here: fee tiers, withholding rules.
public function netCents(Payout $p): int
{
$fee = intdiv($p->grossCents * FEE_BPS[$p->tier], 10000);
$rate = WITHHOLDING_BPS[$p->country] ?? DEFAULT_WITHHOLDING_BPS;
$withholding = intdiv(($p->grossCents - $fee) * $rate, 10000);
return $p->grossCents - $fee - $withholding;
}
// The data team asks for changes here: columns, separators, decimals.
public function toCsv(): string
{
$rows = ['freelancer_id;country;gross;net'];
foreach ($this->payouts as $p) {
$rows[] = implode(';', [$p->freelancerId, $p->country, money($p->grossCents), money($this->netCents($p))]);
}
return implode("\n", $rows);
}
// Support asks for changes here: wording, tone, sign-off.
public function emailBody(Payout $p): string
{
return implode("\n", [
"Hi {$p->freelancerId},",
'',
'Your payout of $' . money($this->netCents($p)) . ' is on its way.',
"Fee tier: {$p->tier}.",
'',
'The Gigloom team',
]);
}
}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.
- Extract function: give a fragment a name
Start by pulling each concern's logic into clearly named functions if it is tangled inside larger methods, so you can see where one axis of change ends and the next begins.
- Extract Class: Split a Class That Does Two Jobs
Give each axis of change its own class: a
PayoutCalculatorfor fees and withholding, aPayoutCsvExporterfor the finance export, and aPayoutEmailfor the message. Each takes the calculator or precomputed net amounts as input. - Move Function: Put Behaviour Next to the Data It Uses
Move helpers such as
moneyand the fee tables next to the concern that actually owns them, so a rule change touches only the calculator module. - Introduce Parameter Object: Bundle Parameters That Travel Together
If the exporter and the email both need the same bundle of computed values, such as gross, fee, withholding and net, pass a single computed breakdown object instead of letting each one call back into the calculator.
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.