データマッパーとは?
データマッパーは、メモリ上のドメインオブジェクトとデータベースの間で、どちらの側も相手を意識することなくデータを転送する責務を持つ独立したレイヤーです。ドメインクラスはストレージコードを一切持たず、マッパーが読み込み、保存、フィールドのマッピングを扱います。多くの ORM は内部でこのパターンを実装しています。
なぜ重要か
永続化をドメインオブジェクトから排除することで、モデルは振る舞いとルールに集中できます。また、データベーススキーマとオブジェクトモデルがある程度独立して進化できるようになります。
関連ガイド
What Is the Active Record Pattern?The active record pattern gives each object both its data and the methods to load, save, and delete itself, c…
What Is the Repository Pattern?The repository pattern provides a collection-like interface for accessing domain objects, hiding the details…
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…