依存性逆転とは?
依存性逆転は、高レベルのポリシーが低レベルの実装に依存すべきではなく、代わりに両者が共有の抽象に依存すべきだという SOLID 原則です。抽象は高レベルのモジュールが所有し、詳細がそれを実装します。これにより、具体的なコードがビジネスロジックへ引き込まれるという通常の方向が逆転します。
なぜ重要か
具体的なクラスではなくインターフェースに依存することで、実装を差し替えたり単独でテストしたりできます。これはレイヤード設計やヘキサゴナル設計を可能にする原則です。
関連ガイド
What Is Inversion of Control?Inversion of control is a design style where a framework or container, rather than your own code, decides whe…
What Are Ports and Adapters?Ports and adapters is the pattern where an application defines interface ports for its needs and adapters imp…
What Is Clean Architecture?Clean architecture organizes code into concentric layers where dependencies point inward, keeping business ru…