"Replace Temp with Query" use cases.

"mszerg" <[email protected]>
Newsgroups gmane.comp.programming.refactoring
Message-ID <[email protected]>
Hi All,

First, I want to say that this is not a joke and kindly ask you to
reply, suppose this will be simple and won't take much of your time :-)

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(..);
}

// this is how X looks like
class X {
private $y;
// lazy getter of y
function getY() {
if (!$this->y) {
$this->y = somehowCreateY();
}
return $this->y;
}
...
}

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(..);
}

In my opinion it is just simpler, not saying 2x faster. But the authors
say that "...according to Fowler's "Replace Temp with Query" refactoring
strategy our version is better". From my conversations with the other
colleagues, this looks like common approach. I suppose that this can be
misunderstanding of the strategy use cases, but I may be wrong. Please,
explain me what is right and wrong in this situation.

--
Thanks in advance,
  Serg Masyutin


[Non-text portions of this message have been removed]



------------------------------------

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/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.