--- robots: noindex, nofollow tags: refactoring --- # Long Parameter List  ## 徵兆與症狀 一個 method/function 有超過三個或四個以上的參數。 ## 出現原因 為了避免使用全域變數,我們會採取將參數傳遞給 method/function,但若在同一個 method/function 內用了多種演算法,則容易產生需要傳遞多個參數,這些參數是用來控制不同演算法的運作。 ## 處理方法 - 某些參數能夠從物件的方法查詢得到,可以使用 `Replace Parameter with Query`。 - 傳遞參數屬於某個物件,可以直接以物件當參數來傳遞 `Preserve Whole Object`。 - 若傳遞的這些資料看似可以合併在一起,可以使用 `Introduce Parameter Object` 先合併這些資料。 - 若參數是某種更改不同行為的旗標(flag),可以使用 `Remove Flag Argument`。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up