Replace Parameter with Methods(以函数取代参数)
生活随笔
收集整理的這篇文章主要介紹了
Replace Parameter with Methods(以函数取代参数)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
對象調(diào)用某個函數(shù),并將其結(jié)果傳遞給另一個函數(shù)
int basePrice = quantity * itemPrice; double discountLevel = getDiscountLevel(); double finalPrice = discountPrice(basePrice, discountLevel);重構(gòu):讓參數(shù)接受者移除該項參數(shù),并直接調(diào)用該函數(shù)
int basePrice = quantity * itemPrice; double finalPrice = discountPrice(basePrice);動機(jī)
?? ?如果函數(shù)可以通過其他途徑獲得參數(shù)值,那么它就不應(yīng)該通過參數(shù)取得該值。過長的參數(shù)列會增加程序閱讀者的理解難度。
總結(jié)
以上是生活随笔為你收集整理的Replace Parameter with Methods(以函数取代参数)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: select ... into ...
- 下一篇: 性能测量工具类——TimeMeasure