Skip to content

MVCとDIP(アーキテクチャパターン)

プロジェクト構成(概要) の詳細です。

MVCアーキテクチャと依存性逆転の原則(DIP)

このプロジェクトはMVC(Model-View-Controller)アーキテクチャに加えて、**依存性逆転の原則(Dependency Inversion Principle, DIP)**を採用しています。

レイヤー構造

依存関係のルール

  1. Controller層

    • Serviceの具体実装に直接依存しない
    • Interface/Service(ServiceInterface)経由のみ依存を許可
    • Factory経由でServiceInterfaceを取得
  2. Service層

    • Repositoryの具体実装に直接依存しない
    • Interface/Repository(RepositoryInterface)経由のみ依存を許可
    • RepositoryInterfaceはFactoryが組み立ててServiceのコンストラクタに注入する(Service自身はFactoryに依存しない)
  3. Factory層

    • 具体実装をインスタンス化する役割
    • Interfaceと実装クラスの対応関係を管理
    • 戻り値はInterface型
  4. Interface層

    • 抽象化の定義のみ
    • 実装層への依存なし(Entity/Dto/Enum等の契約オブジェクトへの依存は許容)
  5. Handler層

    • REST API や Action の登録は、Interface/Adapter(RestApiAdapterInterface, ActionHookAdapterInterface)経由のみ依存
    • WordPress の register_rest_route 等は Infrastructure/WordPress のアダプタ実装に委譲