代码重构之内联函数

2022-04-21 13:27:50 浏览数 (1)

意图

代码语言:javascript复制
- 内部代码和函数名称同样清晰易读,去除无用的间接层

示例

代码语言:javascript复制
/**
 * 内联函数之前
 * Created by luo on 2017/4/18.
 */
public class InlineMethodBefore {
    private Integer _numberOfLateDeliveries ;
    int getRating(){
        return (moreThanFiveLateDliveries()) ? 2 : 1;
    }
    private boolean moreThanFiveLateDliveries() {
        return _numberOfLateDeliveries > 5;
    }
}
/**
 * 内联函数之后
 * Created by luo on 2017/4/18.
 */
public class InlineMethodAfter {
    private Integer _numberOfLateDeliveries ;
    int getRating(){
        return (_numberOfLateDeliveries > 5) ? 2 : 1;
    }
}

0 人点赞