Here is the definition of a repository for Eric Evans in his Domain Driven Design book:
A repository represents all objects of a certain type as a conceptual set (usually emulated). It acts like a collection, except with more elaborate querying capability. […] For each type of object that needs global access, create an object that can provide the illusion of an in-memory collection of all objects of that type.
While I love Doctrine, I really dislike
their repository interface
because it doesn’t look and act like a collection.
And that’s too bad because Doctrine even provides a very good abstraction for collections
doctrine/collection project. It even supports filtering with criterias over collections and repositories.
I know that Doctrine is not targeted at Domain Driven Design only, but I think having a better repository interface would still benefit the project and the users.
Here is a basic repository interface I tend to use instead:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21