Re:"Replace Temp with Query" use cases.

Chet Hendrickson <[email protected]>
Newsgroups gmane.comp.programming.refactoring
Message-ID <[email protected]>
Hello Serg,

The refactorings as compiled by Martin are not a guide to better code,
but a catalog of known transformations that may or not apply to a
given piece of code.  Some of them can be applied in most situations
and others, such as the one under discussion, need to be used in
response to a specific code smell.

"Replace Temp with Query" exists to reduce coupling within a large
method.  It is used to remove an impediment to the creation of a
Composed Method.

If your plan is to transform the method in question via the "Extract
Method" refactoring, you may find a need to replace the temps with
queries, if not, then I would not use it.

chet

Saturday, November 7, 2009, 4:17:52 PM, you wrote:

> 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]




-- 
Best regards,
 Chet Hendrickson                          mailto:[email protected]
 Check out our upcoming CSM Plus courses @
http://hendricksonxp.com/index.php?option=com_eventlist&Itemid=28



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

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.