Monday, November 18, 2013

The Repository Pattern

The repository pattern is an approach to solving the problems of data preservation, organization, and access.  Using the repository pattern abstracts away the storage medium allowing you to not care if your storage is in memory, in XML, in a NoSQL system, or in a SQL system in all its glory.  This is helpful for several reasons.  First, you can unit test without a fully featured database system running requiring significant build-up, coordination, and tear-down before and after each run.  You can rest easier at night knowing that when your boss says that some new database technology is really awesome and you should use it, he won't be upset when you tell him it will take less time than he thought to recode everything.  And another more subtle reason for the repository is to build queries from business rules that are acting upon the repository instead of sprinkling your queries everywhere in your application/business layers.

TLDR: Repositories are your gateway to getting at your application's data.

Martin Fowler's got an excellent write-up on the repository pattern here.

No comments:

Post a Comment