Shotgun surgery means making a number of small changes to a number of different areas in the code, in order to effect a single, coherent change in behavior. It's a
CodeSmell that sometimes results from
CloneAndModifyProgramming, and usually indicates a violation of the
DontRepeatYourself principle. It can also result from poor
SeparationOfConcerns, which itself may be due to lack of language support for effectively abstracting certain
CrossCuttingConcerns (a
CodeSmell caused by a
MissingFeatureSmell rather than any fault of the programmer).
Shotgun surgery (one change in behavior implemented as many changes to code) is the complement of
DivergentChange (many changes in behavior all requiring changes to the same unit of code). Either way you want to arrange things so that, ideally, there is a one-to-one link between common changes and classes. When the changes are all over the place, they are hard to find, and it's easy to miss an important change.
In
ObjectOriented code, you can use
MoveMethod and
MoveField refactorings to put all the changes into a single class. If no current class looks like a good candidate, create one. Often you can use InlineClass
? to bring a whole bunch of behavior together. You get a small dose of divergent change, but you can easily deal with that.