Repository Pattern Standardization of methods

Posted by Nix on Stack Overflow See other posts from Stack Overflow or by Nix
Published on 2010-04-21T15:29:54Z Indexed on 2010/04/21 15:33 UTC
Read the original article Hit count: 205

All I am trying to find out the correct definition of the repository pattern.

My original understanding was this (extremely dubmed down)

  • Separate your Business Objects from your Data Objects
  • Standardize access methods in data access layer.

I have really seen 2 different implementations.

Implementation 1 :

public Interface IRepository<T>{
      List<T> GetAll();
      void Create(T p);
      void Update(T p);
}


public interface IProductRepository: IRepository<Product> {
      //Extension methods if needed
       List<Product> GetProductsByCustomerID();
}

Implementation 2 :

public interface IProductRepository {
      List<Product> GetAllProducts();
      void CreateProduct(Product p);
      void UpdateProduct(Product p);
      List<Product> GetProductsByCustomerID();
}

Notice the first is generic Get/Update/GetAll, etc, the second is more of what I would define "DAO" like.

Both share an extraction from your data entities. Which I like, but i can do the same with a simple DAO. However the second piece standardize access operations I see value in, if you implement this enterprise wide people would easily know the set of access methods for your repository.

Am I wrong to assume that the standardization of access to data is an integral piece of this pattern ?

Rhino has a good article on implementation 1, and of course MS has a vague definition and an example of implementation 2 is here.

© Stack Overflow or respective owner

Related posts about design-patterns

Related posts about c#