Replace Method with Method Object

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: You have a long method that uses local variables in such a way that you cannot apply Extract Method. //class Order... double price() { double primaryBasePrice; do...)
 
Line 8: Line 8:
 
         double tertiaryBasePrice;
 
         double tertiaryBasePrice;
 
         // long computation;
 
         // long computation;
    ...
+
        ...
}
+
    }
  
 
Turn the method into its own object so that all the local variables become fields on that object. You can then decompose the method into other methods on the same object.<br><br>
 
Turn the method into its own object so that all the local variables become fields on that object. You can then decompose the method into other methods on the same object.<br><br>
Line 15: Line 15:
  
 
== Additional Resources ==
 
== Additional Resources ==
[[http://sourcemaking.com/refactoring/replace-method-with-method-object | SourceMaking.com]]
+
[http://sourcemaking.com/refactoring/replace-method-with-method-object SourceMaking.com]

Revision as of 00:11, 7 August 2009

You have a long method that uses local variables in such a way that you cannot apply Extract Method.


   //class Order...
   double price() {
       double primaryBasePrice;
       double secondaryBasePrice;
       double tertiaryBasePrice;
       // long computation;
       ...
   }

Turn the method into its own object so that all the local variables become fields on that object. You can then decompose the method into other methods on the same object.

Replace.gif

Additional Resources

SourceMaking.com