Shotgun Surgery
Updated 2026-07-30
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.
Introduction
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/1Practice this model in one real situation:
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
- refactoring.guruhttps://refactoring.guru/smells/shotgun-surgeryverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS