Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

書籍 Refactoring to Patterns | Code Smells

パンくず

書籍 Refactoring to Patterns
Code Smells

概要

リファクタリングが必要となる「コードの臭い」について

内容

リファクタリングが必要になるコードにはそれぞれの問題特有の「臭い」があります。by Martin Fowler
この「臭い」をかぎわける能力を身につけることで、各問題に対してどのようなリファクタリングを行えばよいか
が分かります。
ここで、臭いとリファクタリングの内容を表にまとめます。

臭い表

Smell Refactoring リファクタリング
Duplicated Code Form Template Method テンプレートメソッドによる変換
Introduce Polymorphic Creation with Factory Method ファクトリメソッドによる生成でポリモルフィズムを導入
Chain Constructors コンストラクタの連鎖
Replace One/Many Distinctions with Adapter アダプターによる一つまたは多数の判別置換
Extract Composite 集約の抽出
Unify Interfaces with Adapter アダプターとインターフェースの統一
Introduce Null Object Nullオブジェクトの導入
Long Method Compose Method 構成メソッド
Move Accumulation to Collecting Parameter 集積したパラメータの移動
Replace Conditional Dispatcher with Command コマンドによる条件分岐の置換
Move Accumulation to Visitor 集積をビジターへ移動
Replace Conditianal Logic with Strategy ストラテジによる条件分岐の置換
Conditional Complexity Replace Conditianal Logic with Strategy ストラテジによる条件分岐の置換
Move Embellishment to Decorator 飾りをデコレーターに移動
Replace State-Altering conditionals with State 状態変化による分岐をステートに置換
Introduce Null Object Nullオブジェクトの導入
Primitive Obsession Replace Type Code with Class タイプコードをクラスに置換
Replace State-Altering Conditionals with State 状態変化による分岐をステートに置換
Replace conditional Logic with Strategy ストラテジによる条件分岐の置換
Replace Implicit Tree with Composite 暗黙の木構造を集約に置換
Replace Implicit Language with Interpreter インタープリターによる暗黙の言語の置換
Move Embellishment to Decorator 飾りをデコレーターに移動
Encapsulate Composite with Builder ビルダーによる集約のカプセル化
Indecent Exposure Encapsulate Classes Knowledge to Factory クラスの情報をファクトリーへカプセル化
Colution Sprawl Move Creation Knowledge to Factory 生成の情報をファクトリーへ移動
Alternative Classes
with Different Interfaces
Unify Interfaces with Adapter アダプターによるインターフェースの統一
Lazy Class Inline Singleton シングルトンのインライン化
Large Class Replace Conditianal Dispatcher with Command コマンドによる条件分岐の置換
Replace State-Altering Conditianals with State 状態変化による分岐をステートに置換
Replace Implicit Language with Interpreter インタープリターによる暗黙の言語の置換
Switch Statements Replace Conditianal Dispatcher with Command コマンドによる条件分岐の置換
Move Accumulation to Visitor 集積をビジターへ移動
Combinatorial Explosion Replace Implicit Language with Interpreter インタープリターによる暗黙の言語の置換
Oddball Solution Unify Interfaces with Adapter アダプターによるインターフェースの統一