Shotgun Surgery

Shotgun Surgery is usually a more obvious symptom that reveals another smell.

Symptoms

  • You have to make the same small change across several different files.
  • Changes become difficult to manage because they are hard to keep track of.

Make sure you look for related smells in the affected code:

Solutions

Prevention

  • If your changes become spread out because you need to pass information between boundaries for dependencies, try inverting control.
  • If you find yourself repeating the exact same change in several places, make sure that youIf you find yourself repeating the exact same change in several places, make sure that you Don’t Repeat Yourself
  • If you need to change several places because of a modification in your dependency chain, such as changing user.plan.price to user.account.plan.price, make sure that you’re following the Law of Demeter
  • If conditional logic is affected in several places by a single, cohesive change, make sure that you’re following Tell, Don’t Ask