Pros:

  • Repositories hide complex queries.
  • Repository methods can be used as transaction boundaries.
  • ORM can easily be mocked

Cons:

  • ORM frameworks offer already a collection like interface to persistent objects, what is the intention of repositories. So repositories add extra complexity to the system.
  • combinatorial explosion when using findBy methods. These methods can be avoided with Criteria objects, queries or example objects. But to do that no repository is needed because a ORM already supports these ways to find objects.
  • Since repositories are a collection of aggregate roots (in the sense of DDD), one have to create and pass around aggregate roots even if only a child object is modified.

Questions:

  • What pros and cons do you know?
  • Would you recommend to use repositories? (Why or why not?)
Edit
Report