LoginSignup
2
2

More than 3 years have passed since last update.

リファクタリング・カタログ(抜粋)

Posted at

原本

マーチン・ファウラー著「Refactoring(洋書)」
が所属するThoughtWorks社が公開している、リファクタリングの方法をカタログ化したもの
- https://refactoring.com/catalog/

一部抜粋した一覧

適切な名前をつける

  • シンボリック定数によるマジックナンバーの置き換え
    • Replace Magic Number with Symbolic Constant
  • メソッド名の変更
    • Rename Method
  • 説明用変更の導入
    • Introduce Explaining Variable
  • 一時変数の分離
    • Split Temp

一時変数をなくす

  • 一時変数のインライン化
    • Inline Temp
  • 問い合わせによる一時変数の置き換え
    • Replace Temp with Query
  • 制御フラグの削除
    • Remove Control Flag

条件分岐をシンプルにする

  • 条件記述の分解
    • Decompose Conditional
  • 重複した条件記述の断片の統合
    • Consolidate Duplicate Conditional Fragments
  • ガード説による入れ子条件記述の置き換え
    • Replace Nested Conditional with Guard Clauses
  • 条件記述の統合
    • Consolidate Conditional Expression
  • ヌルオブジェクトの導入
    • Introduce Null Object
  • ポリモーフィズムによる条件記述の置き換え
    • Replace Conditional with Polymorphism

条件判定か例外か

  • 例外によるエラーコードの置き換え
    • Replace Error Code with Exception
  • 条件判定による例外の置き換え
    • Replace Exception with Test

オブジェクトを作る

  • Factory Method によるコンストラクタの置き換え
    • Replace Constructor with Factory Method

クラスやインタフェースを抜き出す

  • クラスの抽出
    • Extract Class
  • クラスのインライン化
    • Inline Class
  • サブクラスの抽出
    • Extract Subclass
  • 階層の平坦化
    • Collapse Hierarchy
  • スーパークラスの抽出
    • Extract Superclass
  • インタフェースの抽出
    • Extract Interface (カタログにない)

修正できないクラスにメソッドを追加する

  • 外部メソッドの導入
    • Introduce Foreign Method (カタログにない)
  • 局所的拡張の導入
    • Introduce Local Extension (カタログにない)

カプセル化

  • フィールドのカプセル化
    • Encapsulate Field
  • 自己カプセル化フィールド
    • Self-Encapsulate Field
  • コレクションのカプセル化
    • Encapsulate Collection
  • ダウンキャストのカプセル化
    • Encapsulate Downcast (カタログにない)

状況を変えるかどうか

  • setメソッドの削除
    • Remove Setting Method
  • 問い合わせと更新の分離
    • Separate Query from Modifier

フィールドの位置を整える

  • フィールドの移動
    • Move Field
  • フィールドの引き下げ
    • Push Down Field
  • フィールドの引き上げ
    • Pull Up Field

メソッドの位置を整える

  • メソッドの移動
    • Move Method
  • メソッドの引き下げ
    • Push Down Method
  • メソッドの引き上げ
    • Pull Up Method
  • コンストラクタ本体の引き上げ
    • Pull Up Constructor Body

メソッドを作る

  • メソッドの隠蔽
    • Hide Method (カタログにない)
  • メソッドの抽出
    • Extract Method
  • メソッドのインライン化
    • Inline Method
  • アサーションの導入(表明の導入)
    • Introduce Assertion
  • アルゴリズムの取り換え
    • Substitute Algorithm
  • メソッドオブジェクトによるメソッドの置き換え
    • Replace Method with Method Object

メソッドの引数を整える

  • 引数の削除
    • Remove Parameter
  • 引数の追加
    • Add Parameter
  • パラメータへの代入の除去
    • Remove Assignments to Parameters
  • 明示的なメソッド群による引数の置き換え
    • Replace Parameter with Explicit Methods
  • メソッドのパラメータ化
    • Parameterize Method
  • オブジェクトそのものの受け渡し
    • Preserve Whole Object
  • メソッドによる引数の置き換え
    • Replace Parameter with Method
  • 引数オブジェクトの導入
    • Introduce Parameter Object

タイプコードを置き換える

  • クラスによるタイプコードの置き換え
    • Replace Type Code with Class
  • サブクラスによるタイプコードの置き換え
    • Replace Type Code with Subclasses
  • State/Strategyによるタイプコードの置き換え
    • Replace Type Code with State/Strategy
  • フィールドによるサブクラスの置き換え
    • Replace Subclass with Fields

古いシステムへのオブジェクト指向を導入する

  • オブジェクト指向による配列の置き換え
    • Replace Array with Object (カタログにない)
  • オブジェクトによるデータ値の置き換え
    • Replace Data Value with Object
  • データクラスによるレコードの置き換え
    • Replace Record with Data Class
  • 手続き的な設計からオブジェクトへの変換
    • Convert Procedural Design to Objects (カタログにない)

値オブジェクトか参照オブジェクトか

  • 値から参照への変更
    • Change Value to Reference
  • 参照から値への変更
    • Change Reference to Value

モデルとビュー

  • 観察されるデータの複製
    • Duplicate Observed Data (カタログにない)
  • プレゼンテーションとドメインの分離
    • Separate Domain from Presentation

継承と移譲を切り替える

  • 移譲による継承の置き換え
    • Replace Inheritance with Delegation
  • 継承による移譲の置き換え
    • Replace Delegation with Inheritance (カタログにない)

移譲

  • 移譲の隠蔽
    • Hide Delegate
  • 仲介人の除去
    • Remove Middle Man

継承

  • Template Methodの形成
    • From Template Method (カタログにない)
  • 継承の分割
    • Tease Apart Inheritance (カタログにない)
  • 階層の抽出
    • Extract Hierarchy (カタログにない)

クラスの関連

  • 双方向関連の単方向への変更
    • Change bidirectional association to unidirectional (カタログにない)
  • 単方向関連の双方向への変更
    • Change unidirectional association to bidirectional (カタログにない)
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2