title: Comparing refactoring patterns in java
body: <p>I have a simple method and I have applied two refactoring patters- Inline temp and Extract Method Followed by Replace Temp with Query. I would like to know which pattern is more preferable to use in our method. So, this is original method:</p>
  
  <pre><code> public int mymethod(int a, int b) { 
      int t = a * b; 
      if (t &gt; 100) { 
          return t * 0.65; 
      } else { 
          return t * 0.45; 
      } 
  }
  </code></pre>
  
  <p>This is the method with <strong>Inline temp</strong> refactoring:</p>
  
  <pre><code>public int mymethod(int a, int b) {
  
          if (a*b &gt; 100)
          { 
              return (a*b * 0.65);
          }
          else 
          { 
              return (a*b * 0.45);
          } 
      }
  </code></pre>
  
  <p>And finally <strong>Extract method followed by query refactoring</strong>:</p>
  
  <pre><code>public int mymethod(int a, int b) {
    if (t() &gt; 100) {
      return t() * 0.65;
    }
    else {
      return t() * 0.45;
    }
  }
  int t() {
    return a * b;
  }
  </code></pre>
  
  <p>Which one is better to use for our method, you think ? Personally, I think inline temp is better for this method, because Extract method has a new method and program is forced to query that extra method which hits the performance. Am I right ?</p>