🧀
Smells to Refactoring
English
English
  • Introduction
  • Quick Reference Guide
  • Bloaters
    • Long Method
    • Large Class
    • Primitive Obsession
    • Long Parameter List
    • Data Clumps
  • Tool Abusers
    • Repeated Conditional Complexity
    • Refused Bequest
    • Alternative Classes with Different Interfaces
    • Temporary Field
  • Change Preventers
    • Divergent Change
    • Shotgun Surgery
    • Parallel Inheritance Hierarchies
    • Combinatorial Explosion
  • Couplers
    • Feature Envy
    • Inappropriate Intimacy
    • Message Chains
    • Middle Man
    • Indecent Exposure
  • Dispensables
    • Comment
    • Data Class
    • Dead Code
    • Duplicated Code
    • Lazy Class
    • Speculative Generality
    • Oddball Solution
  • Incomplete Library Class
  • 😎About me
Powered by GitBook
On this page
  • Sign of Smell
  • Reason of Smell
  • Refactoring Recipe
  1. Bloaters

Data Clumps

Groups of variables that always appear together should be turned into their own object.

PreviousLong Parameter ListNextTool Abusers

Last updated 1 year ago

Sign of Smell

If deleting one of the data values would make the others meaningless, it is a sign of data clumps. When we find identical groups of variables appearing in different parts of the code, they should be turned into their own classes to avoid data clumps.

Reason of Smell

  • Readability and Understandability: Code that uses data clumps can be difficult to read and understand, especially for developers who are not familiar with the codebase. The relationships between the data elements might not be immediately clear.

  • Duplication: When the same group of data elements is repeated across different parts of the code, it leads to unnecessary duplication. This duplication makes the code harder to maintain because if the data needs to change, it must be updated in multiple places, increasing the risk of inconsistencies.

  • Maintenance Difficulty: Updating or modifying the data becomes a maintenance challenge when it's scattered across the codebase. Any change in the data requires searching through the code to find all occurrences, which can be error-prone and time-consuming.

  • Brittleness: Since the data is spread out across multiple locations, making changes to one part of the code can inadvertently impact other parts that rely on the same data, leading to unexpected and hard-to-diagnose bugs.

Refactoring Recipe

  • Extract Class

  • Introduce Parameter Object

  • Preserve Whole Object

Reference

https://refactoring.guru/smells/data-clumps
https://luzkan.github.io/smells/data-clump