Re: Re: "Replace Temp with Query" use cases.
Amol Jadhav <[email protected]>
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <[email protected]> |
+1 On Mon, Nov 16, 2009 at 6:08 PM, Anthony Williams <[email protected]> wrote: > "mszerg" <[email protected]> writes: > >> Recently I faced the following situation. In our project we have >> several functions with php code like this: >> >> // some global function >> function doSomethingWithX(X $x) { >> $x->getY()->setA(..); >> $x->getY()->setB(..); >> $x->getY()->setC(..); >> ... >> $x->getY()->setZ(..); >> } > >> During code review I suggested the following refactoring: >> >> function doSomethingWithX(X $x) { >> // store reference locally >> $y = $x->getY(); >> // modify fields >> $y->setA(..); >> $y->setB(..); >> $y->setC(..); >> ... >> $y->setZ(..); >> } > > You are doing a load of stuff to the same Y object. This suggests that > the actual setting needs to be a function ON the Y object. e.g. > > function doSomethingWithX(X $x) { > $x->getY()->doSomething(); > } > > class Y > { > function doSomething(){ > $this->setA(..); > $this->setB(..); > $this->setC(..); > ... > $this->setZ(..); > } > ... > } > > I'm not so keen on the x->getY()->doSomething chain either, but that's > not so big a problem here. > > Anthony > -- > Author of C++ Concurrency in Action | http://www.manning.com/williams > just::thread C++0x thread library | http://www.stdthread.co.uk > Just Software Solutions Ltd | http://www.justsoftwaresolutions.co.uk > 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976 > > > > ------------------------------------ > > Yahoo! Groups Links > > > > ------------------------------------ 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/