Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M0040

Shotgun Surgery

Shotgun Surgery
DecidemediumDecision Science
Included
account_tree

Updated 2026-07-30

Loading revision record…

Summary

A poor code structure where a single functional change requires modifying many different classes or modules.

Definition

Shotgun surgery is a code smell in which one conceptually focused change requires coordinated small edits across many classes or modules, often because one responsibility is scattered. It is the opposite direction from divergent change, where one class changes for many different reasons. The name is a software-maintenance metaphor, not a medical procedure.

How to use

Inspect change history for code repeatedly edited together and consider consolidating a shared responsibility. Multi-department approvals are an organizational analogy requiring separate analysis; necessary review procedures are not automatically architectural errors.

Mechanism

A responsibility scattered across locations forces maintainers to remember every coordinated edit; an omission can create inconsistency. Moving related behavior to an appropriate home reduces that coordination, aiming for cohesion rather than one class containing all code.

Practice

In progress 0/1

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

Cases

  • Hypothetical example: orders, invoices, and previews separately implement the same discount rule, requiring synchronized edits. Extract a rule component with a clear interface and verify consistent behavior at all three call sites.

Common pitfalls

  • Editing multiple files is not automatically a smell; interface migrations and cross-layer requirements can justify it. Avoid creating a giant class merely to reduce file count, and distinguish divergent change from shotgun surgery.
Sources

Source support: Explicit

  • link
    refactoring.guruhttps://refactoring.guru/smells/shotgun-surgeryEN · Explicit
    verified
account_treeGenealogyexpand_more

RELATED MODELS