Re: "Replace Temp with Query" use cases.
"c_snufkin" <[email protected]>
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <[email protected]> |
--- In [email protected], "mszerg" <mszerg@...> wrote: > function doSomethingWithX(X $x) { > $x->getY()->setA(..); > $x->getY()->setB(..); > $x->getY()->setC(..); > ... > $x->getY()->setZ(..); > } Refactored to: > function doSomethingWithX(X $x) { > // store reference locally > $y = $x->getY(); > // modify fields > $y->setA(..); > $y->setB(..); > $y->setC(..); > ... > $y->setZ(..); > } It's hard to decide what's best because there are missing details. You didn't say what the parameters of setX are. Technically the repetition is in referring to $y many times. You could: - Add an aggregating method to the $y object that sets everything: $y->setAll(...) - Have each set method return a reference to its own object so you could maybe do something like: $y->setA(...)->setB(...)->setC(...) But then you ignore the more disturbing smells of so many setters and the fact that $y is not immutable. ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/refactoring/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/refactoring/join (Yahoo! ID required) <*> To change settings via email: [email protected] [email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/