Last Revision — April 19, 2022
1 Min Read
---
Bloaters
Data
Between Classes
- Mutable Data Class (antagonistic)
Martin Fowler in book (1999): "Refactoring: Improving the Design of Existing Code"
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.
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].
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
def colorize(red: int, green: int, blue: int):
...
@dataclass(frozen=True)
class RGB:
red: int
green: int
blue: int
def colorize(rgb: RGB):
...