Data class smell
From CSSEMediaWiki
(Difference between revisions)
(add new page) |
m |
||
Line 1: | Line 1: | ||
− | The data class smell is present where a class has only fields, getters, setters and nothing else. | + | 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 == | == Refactoring methods == | ||
Line 5: | Line 5: | ||
* [[Encapsulate Collection]] - if there is collections in the class. This is to ensure unmodifiable, read only collections | * [[Encapsulate Collection]] - if there is collections in the class. This is to ensure unmodifiable, read only collections | ||
* [[Remove Setting Method]] - for fields whose values should not be changed | * [[Remove Setting Method]] - for fields whose values should not be changed | ||
− | * [[Move Method]] or [[Extract Method]] - move method or extract method to move the behavior from the clients to data class | + | * [[Move Method]] or [[Extract Method]] - move method or extract method to move the behavior from the clients (that use the accessors of the data class) to data class |
== See also == | == See also == | ||
* [[Code smells]] | * [[Code smells]] | ||
* [[Keep related data and behavior in one place]] | * [[Keep related data and behavior in one place]] |
Revision as of 10:35, 6 October 2008
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
- Encapsulate Field - if there are public fields
- Encapsulate Collection - if there is collections in the class. This is to ensure unmodifiable, read only collections
- Remove Setting Method - for fields whose values should not be changed
- Move Method or Extract Method - move method or extract method to move the behavior from the clients (that use the accessors of the data class) to data class