java inline_java 代码细节(Inline Method) | 学步园

本文探讨了《重构-----改善既有代码的设计》中提到的Inline Method重构技术。当方法体和其名称一样清晰时,将方法内联到调用者中以消除不必要的间接性。此外,介绍了在遇到一组似乎过度拆分的方法时,如何通过内联和再提取方法来改进代码结构。同时,指出了在处理递归、多个返回点等复杂情况时,需要谨慎使用Inline Method。
摘要由CSDN通过智能技术生成

这个观点来自《重构-----改善既有代码的设计》

A method’s body is just as clear as its name.

Put the method’s body into the body of its callers and remove the method.

int getRating() {

return (moreThanFiveLateDeliveries()) ? 2 : 1;

}

boolean moreThanFiveLateDeliveries() {

return _numberOfLateDeliveries > 5;

}

bcaa46470467988189c0c0673f9ec543.gif

int getRating() {

return (_numberOfLateDeliveries > 5) ? 2 : 1;

}

Motivation

A theme of this book is to use short methods named to show their intention, because these methods lead to clearer and easier to read code. But sometimes you do come across a method in which the body is as clear as the name. Or you refactor the body of the code

into something that is ju

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值