July 14, 2010
Codemanship's Code Smell Of The Week - Data ClassesA key goal of OO design is to minimise depdencies between classes by packaging data and behaviour as close together as we can. In practice, a good rule of thumb for class design is to put fields and methods that use those fields in the same classes. Data classes are classes which just have fields and no behaviour (besides simple getters and setters), and they break this rule of thumb, creating serious dependency issues in your code.
Here, Jason Gorman demonstrates how to refactor data classes by moving the methods (or parts of methods) that use fields of dta classes into the classes that contain those fields.
Download the source code from http://bit.ly/czsOHP
For training and coaching in refactoring, TDD and OO design, visit http://www.codemanship.com
Posted 7 years, 9 months ago on July 14, 2010