Code Smells

Code Smells / Change Preventers / Divergent Change

Divergent Change code smell icon

Divergent Change

Divergent Change smells occur when a single class needs to be edited many times when changes are made outside the class.

class Fish:
    def __init__(self, id, aquarium):
        self.name = aquarium.get_fish_name(id)  # Overly reliant on aquarium's method

The consequence of this is that you can easily cause errors whenever a change is made that the class does not expect, limiting how quickly you can make changes to the code.

The aim should be that changes and classes should have a one-to-one relationship (each change affects only one class). Divergent Change smells are many-to-one (many changes affect one class).

In principle, a class should be self-sufficient. It should not need outside code to work in a particular way.

Divergent Change is the opposite of Shotgun Surgery.

Left chevron Right chevron

Books about code smells

Learn to write better smelling code.

Refactoring: Improving the Design of Existing Code book cover

Refactoring: Improving the Design of Existing Code

Code smells: A Predictor of Remarkable Quality Improvement book cover

Code smells: A Predictor of Remarkable Quality Improvement

Clean Code: A Handbook of Agile Software Craftsmanship book cover

Clean Code: A Handbook of Agile Software Craftsmanship

I receive a commission on sales made from the above affiliate links.