Replace Static Variable with Parameter -- 以参数变量取代静态变量
来源:互联网 发布:尤克里里怎么调音软件 编辑:程序博客网 时间:2024/05/19 02:42
Replace Static Variable with Parameter
A function depending on a static variable needs to be reused in more general context.
依赖一个静态变量的方法需要更多的通用性进行重用。
Add a new parameter to the function and replace all references of the static variable within the function by this new parameter.
为该方法添加一个参数,以参数引用替换所有的静态引用点。
void printValues() {for (int i = 0; i < people.length; i++) {System.out.println(people[i].name+" has salary "+people[i].salary);}}public static void main(String args[]) {...printValues();}
void printValues(PrintStream outfile) {for (int i = 0; i < people.length; i++) {outfile.println(people[i].name+" has salary "+people[i].salary);}}public static void main(String args[]) {...printValues(System.out);}
Motivation
The original function is using a static variable, but you wish either to reuse the function in new project (not containing the static variable) or reuse the function in the same project but in more general context.
原始的方法利用了一个静态变量,但是你希望它重用于其他的新工程或者在一个工程里更为通用。
Mechanics
- If the function calls other functions using the static variable in question, then use this refactoring on all those invoked functions first.
- 如果这个函数应用静态变量调用了其它的函数,那么首先利用此重构处理这些函数。
- Use addParameter to add a new argument to the function
- 使用AddParameter为函数添加新的参数。
- Add the static variable as actual argument to all callers of this function in.
- 在这个方法里,添加一个静态变量作为实际的参数调用。
- Replace all references to the static variable within the function by the new argument
- 以新的参数变量取代所有的静态变量。
- Replace Static Variable with Parameter -- 以参数变量取代静态变量
- 10.8 replace parameter with methods(以函数取代参数)
- Replace Temp With Query(以查询取代临时变量)
- 6.4 Replace Temp with Query(以查询取代临时变量)
- Replace Temp with Query 以查询取代临时变量
- 10.6 replace parameter with explicit methods(以明确函数取代参数)
- 简化函数调用之六 :Replace Parameter with Explicit Methods(以明确函数取代参数)
- 简化函数调用之八 :Replace Parameter with Method(以函数取代参数)
- 重新组织函数--以查询取代临时变量(Replace Temp with Query)
- 重构---重构手法-----以查询取代临时变量(Replace Temp with Query)
- 重构--Replace Temp with Query(以查询取代临时变量)(六)
- C++ static variable(静态变量) 学习
- 重新组织你的函数之四 :Replace Temp with Query(以查询取代临时变量)
- C++ Static Member Variable Initialization 静态成员变量初始化
- 以查询取代临时变量
- static 变量(静态变量)
- bash之参数和变量扩展(parameter and variable expansion)
- static定义静态变量
- ruby on rails & nginx bug修复心得
- 阿里巴巴Dubbo实现的源码分析
- Java学习第二回:JAVA中包的概念了解:似懂非懂
- 懒加载
- 对比大公司招聘要求,看看自己还缺少什么。。。
- Replace Static Variable with Parameter -- 以参数变量取代静态变量
- ACM所需算法知识
- Linux errno汇总
- 关于rails时差8小时的问题解决方案
- 口胡各种程序设计语言
- POJ3273--Monthly Expense
- Visual C++线程同步技术剖析 (转载)
- Android 使用Scroller自动滚动第二种实现
- 多校联合 03 15 A