Replace Parameter with Explicit Methods(以明确函数取代参数)
生活随笔
收集整理的這篇文章主要介紹了
Replace Parameter with Explicit Methods(以明确函数取代参数)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
函數(shù)的行為,完全取決于參數(shù)值
public void setValue(final String name, final int value) {if ("height".equals(name)) {this.height = value;return;}if ("width".equals(name)) {this.width = value;return;}Assert.shouldNeverReachHere(); }重構(gòu):針對(duì)該參數(shù)的每一個(gè)可能值,建立一個(gè)獨(dú)立函數(shù)
public void setHeight(int arg) {this.height = arg; }public void setWidth(int arg) {this.width = arg; }總結(jié)
以上是生活随笔為你收集整理的Replace Parameter with Explicit Methods(以明确函数取代参数)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: EasyMock 简介
- 下一篇: linux捕捉信号sigint失败,为s