版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.csdn.net/asing1elife/article/details/83104311
在方法调用点插入方法本体,然后移除该方法
更多精彩
- 更多技术博客,请移步 asing1elife’s blog
动机
- 一系列组织不合理的方法相互调用,可以通过内联方法将其合并成一个大型方法,在通过 6.1 Extract Method 提炼方法 将这些代码重新提炼
- 过多的使用间接层,导致系统中大部分方法看上去都只是另一个方法的简单委托
案例
public int getRating() {
return moreThanFiveLateDeliveries() ? 2 : 1;
}
private boolean moreThanFiveLateDelivers() {
return numberOfLateDeliveries > 5;
}
public int getRating() {
return numberOfLateDeliveries > 5 ? 2 : 1;
}