I have been thinking about the Feature Envy smell lately. Suppose I have an object called DomainObject, that responds to a message "exportTo:someExport". This is basically the DomainObject's way to provide a copy of its internal state:
exportTo:someExport
someExport setX:myX.
someExport setY:myY.
someExport setZ:myZ.
That way, in the data access layer, I could say something like this:
saveNew:someDomainObject
|domainObjectExport|
domainObjectExport := DomainObjectSQLWriter new.
someDomainObject exportTo:domainObjectExport.
db exec:(domainObjectExport generateInsertStatement).
This is an example of Feature Envy. In order to refactor, I should extract this code into a single message to someExport:
exportTo:someExport
someExport setX:myX setY:myY setZ:myZ
However, now the setX:setY:setZ: message suffers from Long Parameter List (imagine 10 parameters instead of 3). Is there a way to have it both ways, or is Feature Envy only a bad smell if data is flowing out of the object you are envious of?