Data Clump — Code Smells Catalog Skip to content

Data Clump

Bloaters Data Code SmellDesign Smell Between Class

red, green, and blue passed separately to every function that needs a color. The same variables travel together everywhere, never packaged into the object they're quietly begging to become.

2 min read 1 source

Overview

Data Clumps refer to a situation in which a few variables are passed around many times in the codebase instead of being packed into a separate object. Think of it as having to hold different groceries in a grocery store by hand instead of putting them into a basket or at least a handy cardboard box - this is just not convenient. Any set of data items that are permanently or almost always used together, but are not organized jointly, should be packed into a class. An example could be the RGB values held separately rather than in an RGB object.

Causation

Developers often believe that a pair of variables is unworthy of creating a separate instance for them that could aggregate them under a common abstraction [1].


Problems

🔍
Hidden Abstraction

Variables grouped into objects of their own increase the readability of the code, thus making the concept clearer.

🧩
More Complex APIs

Components Interfaces complexity increases with the number of accepted data ---

Example

1def colorize(red: int, green: int, blue: int):
2    ...
PYTHON

Refactoring

  • Extract Class
  • Introduce Parameter Object

Sources

Browse All 56 Smells