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 のアダプタ実装に委譲
  6. Admin層

    • Repositoryの具体実装に直接依存しない
    • ビジネスロジックは Interface/Service(ServiceInterface)経由でアクセスする
    • 読み取り中心のデータ取得は Interface/Repository(RepositoryInterface)経由を許容する(Deptrac で検証。具体 Repository 実装への依存は禁止)
    • 一覧などの読み取り専用参照は RepositoryInterface でよいが、登録・更新・削除などの書き込みは ServiceInterface 経由とする
    • 参考実装: EventMasterAdminPage(ServiceInterface のみ)、AnaSloAdminPage / TwitterSummaryAdminPage(ServiceInterface に加え RepositoryInterface を利用する場合あり)