本エントリーでは次の点を整理したいと思います。 ServiceLocatorパターンとは何か? Dependency Injection(以降DI)パターンとは何か? DI Containerとは何か? これらを使うと何がうれしいのか? ServiceLocatorとDI何が違うのか? ServiceLocatorとDIどちらを使うべきか? はじめに 問題点 利用箇所の結合度をさげる 生成箇所の結合度をさげる ServiceLocatorパターン Dependency Injectionパターンを使う Dependency Injection Container ServiceLocatorとDependency Injection いずれを利用すべきか? 本来不要であるServiceLocatorへの依存が発生してしまう 依存関係が分かりにくくなる テストが困難になる はじめに さて現代