方法一:Extract Method(提炼函数)
来源:互联网 发布:mac使用webpack 编辑:程序博客网 时间:2024/06/10 11:57
名称:Extract Method(提炼函数)
概述:有一段代码可以被组织在一起并独立出来。将这段代码放进一个独立函数中,并让函数名称解释该函数的用途。
void printOwing(double amout)
{
printBanner();
//print details
System.out.println("name: " + _name);
System.out.println("amount" + amount);
}
void printOwing(double amount)
{
printBanner();
printDetails(amount);
}
void printDetails(double amount)
{
System.out.println("name: " + _name);
System.out.println("amount" + amount);
}
动机:当看见一个过长的函数火着一段需要注释才能让人明白的代码时,可以用Extract Method来进行重构。
这样做有三个好处:
- 每个函数的粒度小,容易被重用
- 使高层函数读起来像一系列注释
- 如果函数都是细粒度,那函数的覆写也会更容易
做法:
- 创造一个新函数,根据函数的意图来对它命名(以函数“做什么”命名,而不是“怎样做”命名)。只要新函数的名称能够以更好的方式说明代码的意图,你就应该提炼,如果想不到好名称,就别动了
- 将提炼出的代码从源函数复制到新建的目标函数
- 方法一:Extract Method(提炼函数)
- Extract Method( 提炼函数 )
- Extract Method 提炼函数
- 提炼方法 Extract Method
- 6.1 Extract Method(提炼函数)
- 读书笔记-重构 - Extract Method(提炼方法)
- java 重构学习2:提炼函数(Extract method)
- 重构--Extract Method(提炼函数)(四)
- Eclipse Extract Method 方法实现 (一)
- 重新组织你的函数之一 :Extract Method(提炼函数)
- 《重构 改善既有代码的设计》学习笔记 2 -- Extract Method(提炼函数)
- Extract Class(提炼类)
- 提炼常量 Extract Constant
- Eclipse Extract Method 方法实现(二)
- Extract Method
- Extract Method
- 7.3extract class(提炼类)
- 11.6 extract subclass 提炼子类
- 什么是SDK编程
- WinCE系统启动时自动运行应用程序
- 缓冲区反转
- 动态生成文件,然后下载,备忘
- Novell 050-708认证介绍
- 方法一:Extract Method(提炼函数)
- Android一些控件的使用
- NS-3有线网络脚本编写步骤
- 蓝屏的办法
- sql2005 中操作数据库
- 没有函数数组,只有函数指针数组
- c小结--听课笔记
- 我的技术博客
- ETL工具——kettle插件开发(基础篇)