A repository is an object that transfers data between the business layer of an application and its data store. It appears to the developer-user as a factory that generates objects or collections in response to queries. Updated objects and collections can be passed back to the repository for persistence to the data store.
A Repository provides a clean separation between business and persistence logic. Repositories are often used with Object/Relational Management (ORM) frameworks. A repository can simply wrap the methods of an ORM, or it can provide a framework-neutral interface that isolates the business layer of the application from the ORM, allowing the ORM to be replaced at a later date without modification to the business layer.
The Repository Pattern is described by Martin Fowler in Patterns of Enterprise Application Software.
It can also be viewed as a:
- Software Repository: a storage location from which software packages may be retrieved and installed on a computer.
- Version Control Repository: an on-disk data structure which stores metadata for a set of files and/or directory structure.