Description
Change Preventer is a piece of code that prevents a programmer to make any changes, as a simple change in one place needs many changes in other places.
These make development more complicated and expensive, as they prevent programmers to touch certain parts of the code.
Here is a list of commonly observed change preventers.
- Divergent Change
- Parallel Inheritance Hierarchies
- Shotgun Surgery
Divergent Change
Problem: You find yourself having to change many unrelated methods when you make changes to a class. For example, when adding a new product type you have to change the methods for finding, displaying, and ordering products.
Solution: Use the mentioned refactoring techniques to avoid these kinds of code smells.
- Extract Class
- Extract Superclass
- Extract Subclass
Shotgun Surgery
Problem: Making any modifications requires that you make many small changes to many different classes.
Solution: Use the mentioned refactoring techniques to avoid these kinds of code smells.
- Move Method
- Move Field
- Inline Class
Parallel Inheritance Hierarchies
Problem: Whenever you create a subclass for a class, you find yourself needing to create a subclass for another class.
Solution: Use the mentioned refactoring techniques to avoid these kinds of code smells.
- Move Method
- Move Field
Overall
We now know how to find and resolve change preventers in the code to improve the code quality.