Tinku
Tinku

Reputation: 1608

Is Repository pattern an overkill

I have been using Repository pattern (DDD and POEAA) for some time. However some of our team members have argued that it is just an extra layer of abstraction and unnecessary. I can seen some benefit in their arguments. Modern ORM solutions (NHibernate or EF) have almost everything you need. I searched and found some article like this and counterargument on this topic. So Is repository pattern an overkill?

Upvotes: 10

Views: 1391

Answers (3)

Shane Courtrille
Shane Courtrille

Reputation: 14097

The one reason we use Repositories in our project is that it enforces who our Aggregate Roots are (we only allow repositories for ARs) so that you work through the AR properly instead of querying for whatever strikes your fancy.

And as Al mentioned.. it does provide a nice interface to mock out during unit tests.

Upvotes: 1

Kimi
Kimi

Reputation: 14099

Mocking data access in unit tests is the main reason I use repository interfaces. Another reason maintainability - you can easily implement caching strategies, or switch to other data access implementation, like getting data from the service instead of DB.

Upvotes: 4

Brandon Satrom
Brandon Satrom

Reputation: 1821

It depends, mostly on the complexity of your problem and the role your Domain Model plays in the solution. For simple solutions, Repository is probably overkill. But for complex domains with a robust language and evolving needs/requirements, the Repository is a nice, clean abstraction that owns the domain object lifecycle. Many ORMs will do much of this, but, in a complex domain, there will always be some domain activity that makes sense in a repository and which is not supported by an ORM out of the box.

Bottom line: it depends on the context.

Upvotes: 12

Related Questions