Data clumps smell

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (See also)
m (Reverted edits by Ebybymic (Talk); changed back to last version by Filip Kujikis)
 
(7 intermediate revisions by 3 users not shown)
Line 2: Line 2:
  
 
Martin Fowler suggests replacing these clumps with a single object. In the example above the start and end could be replaced by a "Range" class. Doing this refactoring decreases the size of parameter lists when the values are passed around. This is one solution to the [[Long parameter list smell]]. You can also discover some nice behaviour when you extract the data into an object. For the Range example, you often want to know if a value is within the start and end range, so you could define an "includes" method in the Range class to check for this easily.
 
Martin Fowler suggests replacing these clumps with a single object. In the example above the start and end could be replaced by a "Range" class. Doing this refactoring decreases the size of parameter lists when the values are passed around. This is one solution to the [[Long parameter list smell]]. You can also discover some nice behaviour when you extract the data into an object. For the Range example, you often want to know if a value is within the start and end range, so you could define an "includes" method in the Range class to check for this easily.
 +
 +
== Common Refactorings ==
 +
* [[Extract Class]] - though this causes a [[Data class smell]] if the resulting class does not define useful behaviour.
 +
* [[Introduce Parameter Object]]
 +
* [[Preserve Whole Object]]
  
 
== See also ==
 
== See also ==
Line 7: Line 12:
 
* [[Design maxims]]
 
* [[Design maxims]]
 
* [[Code smells]]
 
* [[Code smells]]
 +
  
 
{{Template:CodeSmells}}
 
{{Template:CodeSmells}}
  
 
[[Category:Code smells]]
 
[[Category:Code smells]]

Latest revision as of 03:21, 25 November 2010

Data clumps are groups of data items that are related and are always used or passed around together. They are often primitive values. An example of this is a "start" variable and an "end" variable.

Martin Fowler suggests replacing these clumps with a single object. In the example above the start and end could be replaced by a "Range" class. Doing this refactoring decreases the size of parameter lists when the values are passed around. This is one solution to the Long parameter list smell. You can also discover some nice behaviour when you extract the data into an object. For the Range example, you often want to know if a value is within the start and end range, so you could define an "includes" method in the Range class to check for this easily.

Common Refactorings

See also



Personal tools