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
Variables grouped into objects of their own increase the readability of the code, thus making the concept clearer.
Components Interfaces complexity increases with the number of accepted data ---
Example
1def colorize(red: int, green: int, blue: int):
2 ...Refactoring
- Extract Class
- Introduce Parameter Object
Sources
- ORIGIN1999 · ISBN 978-0201485677