--- robots: noindex, nofollow tags: refactoring --- # Data Clumps  ## 徵兆與症狀 你會注意到某些資料經常一起出現在程式碼的不同地方。例如:method/function 的參數列,變數欄位,這表示這群資料應該聚集在一起。 ## 出現原因 如果想要確認某群資料是否為 `data clump`,只要刪掉其中一個資料,然後看看剩下資料是否仍然合理,如果不再合理的話,通常是這群資料應該距離在一起的好徵兆。 ## 處理方法 - 如果這些資料是某些類別的欄位,可以用 `Extract Class` 來抽取。 - 如果這些資料通常用在 method/function 的參數列傳遞,可以使用 `Introduce Parameter Object` 或 `Preserve Whole Object`。 - 接著可以看看使用這些欄位或資料的程式碼,或許把對資料操作的行為也搬進去抽取出的 data class 是個好主意。
×
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