Data class smell
From CSSEMediaWiki
(Difference between revisions)
(→Validity) |
|||
Line 1: | Line 1: | ||
+ | ---- | ||
+ | <div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;"> | ||
+ | ---- | ||
+ | =[http://imygijesusy.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]= | ||
+ | ---- | ||
+ | =[http://imygijesusy.co.cc CLICK HERE]= | ||
+ | ---- | ||
+ | </div> | ||
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). | ||
Revision as of 10:45, 24 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
- 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
- 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
See also