重构5-Pull Up Field(字段上移)
2016-08-18 16:56
495 查看
我们来看看一个和上移方法十分类似的重构。我们处理的不是方法,而是字段。
在这个例子中,两个子类中包含重复的常量。为了提高复用性我们将字段上移到基类中,并简化其名称。
来自为知笔记(Wiz)
public abstract class Account{} public class CheckingAccount extends Account{ private Double _minimumCheckingBalance = 5D; } public class SavingsAccount extends Account{ private Double _minimumCheckingBalance = 5D; }
在这个例子中,两个子类中包含重复的常量。为了提高复用性我们将字段上移到基类中,并简化其名称。
public abstract class Account{ private Double _minimumCheckingBalance = 5D; } public class CheckingAccount extends Account{} public class SavingsAccount extends Account{}
来自为知笔记(Wiz)
相关文章推荐
- 重构手法57:Pull Up Field (字段上移)
- 重构第5天:提升字段(Pull Up Field)
- 处理概括关系之一 :Pull Up Field(值域上移)
- 重构手法58:Pull Up Method (方法上移)
- 读书笔记-重构-Pull Up Field(把属性移入父类)
- 重构3-Pull Up Method(方法上移)
- 重构之Pull Up Field ,Push Down Field 与Rename(method,class,parameter)笔记
- 重构手法59:Pull Up Constructor Body (构造函数本体上移)
- 重构第6天:降低字段(Push Down Field)
- 重构手法18:Self Encapsulate Field (自封装字段)
- 重构手法61:push down field (字段下移)
- 处理概括关系之三 :Pull Up Constructor Body(构造函数本体上移)
- 31天重构指南之三: 提升方法(pull up )
- Refactoring Day 5 : Pull Up Field
- 重构改善既有代码设计--重构手法18:Self Encapsulate Field (自封装字段)
- 重构之Pull up Method 与Push Down Method
- 重构第3天:方法提公(Pull Up Method)
- 重构之Pull up Method 与Push Down Method
- 重构6-Push Down Field(字段下移)
- Refactoring--Pull Up /Push Down Method or Field