IRepository(Of Customer) vs. CustomerRepository

time to read 1 min | 187 words

Using IRepository(Of Customer):

Customer[] customersWithUnpaidOrders = repository.FindAll(@"select c from Customer c, Order o 
where o.Customer = c and o.Status = OrderStatus.Unpaid"

Using CustomerRepository:

Customer[] customersWithUnpaidOrders = repository.GetCustomersWithUnpaidOrders();

The difference is the level of abstraction that is used. In the first case, the code define the question explicitly, using the generic repository to pose the question. In the second, it is the CustomerRepository responsability to get the data.

The first is much more flexible, but it is harder to test. The second is much easier to test (but require better integration testing to check that it the repository is actaully doing its job), and is more intention revealing.