リポジトリパターンとは?
リポジトリパターンは、ドメインオブジェクトをメモリ上のコレクションのように追加・検索・削除するメソッドを公開する抽象です。基盤となるデータベースのクエリやマッピングを、ドメインに馴染むインターフェースの背後に隠します。ビジネスコードは、特定の永続化技術ではなくリポジトリの契約に依存します。
なぜ重要か
データアクセスをリポジトリの背後に集約することで、クエリの詳細をビジネスロジックから排除し、永続化を差し替え可能にします。また、テストでデータをスタブ化する自然な場所も提供します。
関連ガイド
What Is a Unit of Work?A unit of work tracks changes to objects during a business operation and commits them together as a single co…
What Is a Data Mapper?A data mapper is a layer that moves data between objects and a database while keeping the two independent, so…
What Is an Aggregate Root?An aggregate root is the single entity through which all access to a cluster of related domain objects flows,…