Data class smell

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m
m (Reverted edits by Ebybymic (Talk); changed back to last version by Lukas Korsika)
 
(8 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 
The data class smell is present where a class has only fields, getters, setters and nothing else. It lacks the behaviours that make it a proper, stand-alone class (and consequently, the instantiated object).
 
The data class smell is present where a class has only fields, getters, setters and nothing else. It lacks the behaviours that make it a proper, stand-alone class (and consequently, the instantiated object).
  
== Refactoring methods ==
+
== Validity ==
 +
 
 +
What exactly is wrong with data classes? Data classes always seemed useful and necessary to me - for example, geometric constructs such as points and vectors (Have you tried types ? Are you using the right language ? (Let's move this to the discussion page, chaps --[[User:Lukas Korsika|Lukas Korsika]] 00:32, 21 October 2010 (UTC) )).  Data classes can definitely be misused, but I don't think this smell should be considered an automatic refactoring job.
 +
 
 +
== Refactoring techniques ==
 
* [[Encapsulate Field]] - if there are public fields
 
* [[Encapsulate Field]] - if there are public fields
 
* [[Encapsulate Collection]] - if there is collections in the class. This is to ensure unmodifiable, read only collections is returned
 
* [[Encapsulate Collection]] - if there is collections in the class. This is to ensure unmodifiable, read only collections is returned
Line 8: Line 12:
  
 
== See also ==  
 
== See also ==  
* [[Code smells]]
+
* [[Eliminate irrelevant classes]]
 
* [[Keep related data and behavior in one place]]
 
* [[Keep related data and behavior in one place]]
 +
* [[Code smells]]
 +
* [[Refactoring]]
 +
 +
{{Template:CodeSmells}}
 +
 +
[[Category:Code smells]]

Latest revision as of 03:07, 25 November 2010

The data class smell is present where a class has only fields, getters, setters and nothing else. It lacks the behaviours that make it a proper, stand-alone class (and consequently, the instantiated object).

Validity

What exactly is wrong with data classes? Data classes always seemed useful and necessary to me - for example, geometric constructs such as points and vectors (Have you tried types ? Are you using the right language ? (Let's move this to the discussion page, chaps --Lukas Korsika 00:32, 21 October 2010 (UTC) )). Data classes can definitely be misused, but I don't think this smell should be considered an automatic refactoring job.

Refactoring techniques

See also


Personal tools