`
blue2048
  • 浏览: 178863 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

重构二 Replace Method with Method Object

阅读更多
重构过程中,我们经常会使用Extract Method,当被抽取的函数局部变量繁杂时,Extract Method往往难以进行...
这时候我们可以使用Replace Method with Method Object来简化分析局部变量的工作。
其核心思想是使用类的成员属性保存变量,以达到在对象范围内变量的使用,而不用在函数间传递。

需要做的工作,有以下几步。
1.创建新对象,域中包含被抽取方法对象的引用和抽取函数中所有涉及到的局部变量
2.新建一个方法,并命名,将被抽取函数所有内容移至该函数内
3.在被抽取函数体内实例化新对象,并掉用其新建的方法

finally,
在新建的对象内,对新建的函数进行Extract Method,由于有成员属性的保障,使重构异常容易
分享到:
评论

相关推荐

    重构-改善既有代码的设计(中文版)

     Replace Method with Method Object 用方法对象代替方法   Substitute Algorithm 替换算法  Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field 移动...

    重构-改善既有代码的设计+中文版

     Replace Method with Method Object 用方法对象代替方法   Substitute Algorithm 替换算法  Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field 移动...

    重构-改善既有代码的设计 中文版.pdf

    6.8 Replace Method with Method Object(以函数对象取代函数) 6.9 Substitute Algorithm(替换你的算法) 第7章 在对象之间移动特性 7.1 Move Method(搬移函数) 7.2 Move Field(搬移值域) 7.3 Extract Class...

    重构_改善既有代码的设计[高清版]中文版

     Replace Method with Method Object 用方法对象代替方法   Substitute Algorithm 替换算法  Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field 移动...

    重构 改善既有代码的设计

     Replace Method with Method Object 用方法对象代替方法   Substitute Algorithm 替换算法  Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field ...

    重构——改善既有代码的设计

     Replace Method with Method Object 用方法对象代替方法   Substitute Algorithm 替换算法  Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field 移动...

    重构,改善既有代码的设计

     Replace Method with Method Object 用方法对象代替方法   Substitute Algorithm 替换算法  Chapter 7:Moving Features Between Objects 在对象之间移动特性  *Move Method 移动方法   Move Field 移动...

    重构:改善既有代码的设计.[美]Martin Fowler.epub【文字版手机格式】

    6.8 Replace Method with Method Object(以函数对象取代函数) 6.9 Substitute Algorithm(替换算法) 第7章 在对象之间搬移特性 7.1 Move Method(搬移函数) 7.2 Move Field(搬移字段) 7.3 Extract Class(提炼类) ...

    重构-改善既有代码的设计

    6.8 Replace Method with Method Object(以函数对象取代函数) 135 6.9 Substitute Algorithm(替换算法) 139 第7章 在对象之间搬移特性 141 7.1 Move Method(搬移函数) 142 7.2 Move Field(搬移字段...

    重构-改善既有代码的设计 中文版

    6.8 Replace Method with Method Object(以函数对象取代函数) 6.9 Substitute Algorithm(替换你的算法) 第7章 在对象之间移动特性 7.1 Move Method(搬移函数) 7.2 Move Field(搬移值域) 7.3 Extract Class...

    重构_改善既有代码的设计[高清版]【已进行内容识别处理,可搜索,可编辑+有目录】

    3.2 Long Method C 过长函数) ··· ·· ··· ·· ·· ·· · ·· ·· ·· ····· ····· ·….......... …························· …·············...

    asp.net知识库

    忽略大小写Replace效率瓶颈IndexOf 随机排列算法 理解C#中的委托[翻译] 利用委托机制处理.NET中的异常 与正则表达式相关的几个小工具 你真的了解.NET中的String吗? .NET中的方法及其调用(一) 如何判断ArrayList,...

Global site tag (gtag.js) - Google Analytics