architect-handbook

Software Architect Handbook

View on GitHub

Repository

Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.

Overview

Repository is another layer of abstraction over the data mapping layer where query construction code is concentrated. This can be worthwhile to build when there are a large numer of domain classes or heavy querying, because it helps minimize duplicate query logic.

A Repository acts like an in-memory domain object collection that mediates between the domain and data mapping layers.

Repository supports the objective of achieving a clean separationo and one-way dependency betwen the domain and the data mapping layers.

Client objects construct query specifications declaratively and submit them to Repository for satisfaction. Objects can be added to and removed from the Repository, as they can from a simple collection of objects, and the mapping code encapsulated by the Repository will carry out the appropriate operations behind the scenes.

Conceptually, a Repository provdes a more object-oriented view of the persistence layer, encapsulating the set of objects persisted in a data store and the operations performed over them.

How It Works

When to Use It