Tbpgr Blog

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

書籍 Refactoring to Patterns | Protection| Replace Type Code with Class

パンくず

書籍 Patterns to Patterns
Protection
Replace Type Code with Class

概要

Replace Type Code with Classについて

使用する場面

タイプの指定ミスによるバグが想定される場合。

対応方法

Stateパターンを適用します

利点と欠点

利点

・不正なパラメータや比較対策

欠点

・通常よりも、多くのコードを必要とする

サンプル

サンプルはGoFデザインパターンStateパターン