12 June 2008

Repository Pattern

Darryn recently praised the Repository Pattern and I wanted to follow up. I agree with him that this is a very useful pattern to have in your toolbox. I first learned of the pattern in Eric Evan's Domain Driven Design book. The key idea I always remember is that a repository provides transparent interface to persist and retrieve domain objects. This can greatly simplify the code required to implement business functions that interact with numerous domain objects in a service provider object. I usually keep my repositories simple with Save and Finder methods. For example:

public interface ICustomerRepository
{
void Save(Customer);
Customer FindById(int id);

Customer FindByName(string customerName);
...
}

No comments: