制御の反転とは?
制御の反転は、あなたのコードがすべての呼び出しを駆動するのではなく、実行の流れが外部の framework や container に委ねられ、適切なタイミングでコードを呼び出してもらうパターンです。依存性注入はその一般的な形で、コンポーネントが協働相手を自ら生成するのではなく供給されます。コンポーネントは必要なものを記述し、container がそれを結び付けます。
なぜ重要か
オブジェクトの生成とライフサイクルを container に任せることで、コンポーネントは疎結合のまま再構成しやすくなります。結び付けを一元化するため、実装の差し替えは構成の変更で済みます。
関連ガイド
What Is Dependency Inversion?Dependency inversion is the principle that high-level modules and low-level details should both depend on abs…
What Is a Service Locator?A service locator is a registry that code asks for its dependencies at runtime, returning the implementation…
What Are Ports and Adapters?Ports and adapters is the pattern where an application defines interface ports for its needs and adapters imp…