June 26, 2010
Codemanship's Code Smell Of The Week - Message ChainsMessage chains are bad from a dependencies point of view. Ideally, objects should keep themselves to themselves and only interact with a small number of direct collaborators (a design principle known as the Law of Demeter). Refactoring messsage chains is a bit like making sausages. You squeeze the code along the chain until every object in the chain is only interacting with direct neighbours, applying Extract Method and Move Method (and the occasional Inline Method to replace getters with the objects they get so that Move Method has an obvious target object to move it to). Easy peasy.
For details on training and coaching in refactoring, TDD and OO design, visit http://www.codemanship.com
Posted 10 years, 9 months ago on June 26, 2010