Shotgun Surgery


Symptoms

  • Making a simple change requires you to change several classes.

Causes

One responsibility is split among several classes. There may be a missing class that would understand the whole responsibility (and which would get a cluster of changes). Or, this can happen through an overzealous attempt to eliminate Divergent Change.

What to Do

  • Identify the class that should own the group of changes. It may be an existing class, or you may need to Extract Class to create a new one.

  • Use Move Field and Move Method to put the functionality onto the chosen class. Once the class not chosen is simple enough, you may be able to use Inline Class to eliminate that class.

Payoff

Reduces duplication. Improves communication. Improves maintainability (as future changes will be more localized).

Contraindications

None identified.

Exercise 41 Shotgun Surgery.

In code you have access to, find examples of this problem. Some frequent candidates:

  • Configuration information.

  • Logging.

  • Persistence.

  • Sometimes it takes two calls on an object to get something common done, and this two-step process is used in several places.




Refactoring Workbook
Refactoring Workbook
ISBN: 0321109295
EAN: 2147483647
Year: 2003
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net