java 代码细节(inline temp)
来源:互联网 发布:石家大唐数据招聘 编辑:程序博客网 时间:2024/04/30 04:23
这个观点来自《重构-----改善既有代码的设计》
You have a temp that is assigned to once with a simple expression, and the temp is getting in the way of other refactorings.
02Replace all references to that temp with the expression.
03 double basePrice = anOrder.basePrice(); return (basePrice > 1000)
04 return (anOrder.basePrice() > 1000)
Motivation
05Most of the time Inline Temp is used as part of Replace Temp with Query, so the real motivation is there. The only time Inline Temp is used on its own is when you find a temp that is assigned the value of a method call. Often this temp isn’t doing any harm and you can safely leave it there. If the temp is getting in the way of other refactorings, such as Extract Method, it’s time to inline it.
Mechanics
06Declare the temp as final if it isn’t already, and compile.
This checks that the temp is really only assigned to once.Find all references to the temp and replace them with the right-hand side of the assignment.
Compile and test after each change.
Remove the declaration and the assignment of the temp.
Compile and test.
- java 代码细节(inline temp)
- java 代码细节(Replace Temp with Query)
- java 代码细节(Inline Method)
- 重构:Inline Temp
- Inline Temp & Replace Temp with Query
- 重构手法:Inline Temp
- Java代码优化细节
- java代码优化细节
- 6.3 Inline Temp(内联临时变量)
- Java代码的汇编细节
- block,inline和inline-block细节对比
- block,inline和inline-block细节对比
- C++那些细节--inline关键字
- Inline Temp( 将临时变量内联化 )
- JAVA代码查错(细节问题)
- java 代码细节(Extract Method)
- java 代码细节(Introduce Explaining Variable)
- java 代码细节(split temporary variable)
- main函数中测试SSH配置环境是否正确
- Learning iOS Game Programming_第05章(图片渲染)_第06.01节_图片渲染类_Texture2D类
- centos 中文乱码解决
- 线性标定校准的实现
- 建立数据元素值为字符型的顺序队列
- java 代码细节(inline temp)
- centos6.3如何安装中文输入法?
- 建立数据域值为字符型的链式队列
- java 代码细节(Replace Temp with Query)
- Spine的使用(With Cocos2d-x)
- Hibernate开发全面流程和开发配置
- centos 6.3下安装QQ2012
- Windows 8 乙肝自测隐私声明
- CentOS 6.2 下安装QQ2012完全可用