Skip to content
StackDecode
System Design
15. Software Design PatternsAnimated walkthrough

Repository Pattern

A collection-like interface to data storage.

The idea

Hides database details so the domain reads and saves objects through a repository.

Watch it work

The steps light up one at a time. Use the controls to pause or step through.

  1. 1Define a repository interface
  2. 2Implement it for the database
  3. 3Domain code calls it
  4. 4Swap implementations in tests
1/4

Step by step

  1. 1Define a repository interface
  2. 2Implement it for the database
  3. 3Domain code calls it
  4. 4Swap implementations in tests

Where it is used

Data access layers.

Watch out for

Leaky abstractions over complex queries.

Related