![]() Make sure that a value is assigned to the variable once and only once within the method. ![]() Nonetheless, if your temp variable is used to cache the result of a truly time-consuming expression, you may want to stop this refactoring after extracting the expression to a new method. By contrast, readable code and the ability to reuse this method in other places in program code-thanks to this refactoring approach-are very noticeable benefits. But with today’s fast CPUs and excellent compilers, the burden will almost always be minimal. ![]() The honest answer is: yes, it is, since the resulting code may be burdened by querying a new method. This refactoring may prompt the question of whether this approach is liable to cause a performance hit. Slimmer code via deduplication, if the line being replaced is used in multiple methods. It’s much easier to understand the purpose of the method getTax() than the line orderPrice() * 0.2. The same expression may sometimes be found in other methods as well, which is one reason to consider creating a common method. This refactoring can lay the groundwork for applying Extract Method for a portion of a very long method.
0 Comments
Leave a Reply. |