Reputation: 430
If you create a repository class that encapsulates all of your persistence logic for a given entity, such as PersonRepository, but your repository class does not implement the Unit of Work pattern or the Identity Map pattern, is it still considered a repository? In other words, are Unit of Work and Identity Map required for a repository implementation, or can we just call any class that encapsulates our persistence logic a repository?
I should add one thing. If a repository does not require these patterns and it's really just a container for persistence methods, then what is the difference between a repository and a DAO (Data Access Object)? Are we just creating multiple names for the same object or are we missing part of what a repository is supposed to be?
Upvotes: 11
Views: 2220
Reputation: 39950
I'd say the Repository and Unit of Work patterns are orthogonal.
Very frequently, I want a single unit of work to span operations on multiple repositories, so an implementation of that would belong into a higher layer.
Upvotes: 3
Reputation: 7674
When considering separation of concerns, remember that your Repository will have the data storage implementation methods, allowing you to keep that out of your main code. This is helpful for unit testing as well as eventually swapping out your data storage implementation altogether (an example of a data storage implementation would be LINQ-to-SQL in ASP.NET.)
Upvotes: 1
Reputation: 19765
Building on what Sii said - it seems better to me if the repository and the unit of work aren't related. Seperation of concerns?
Upvotes: 1
Reputation: 13509
Yes, it is still a repository.
As for if Repository == DAO, I think Repository should be on business logic layer and DAO should be on data access layer, i.e. I think they are on different layers. So as I understand, Repository calls DAO methods to load and persist data.
Upvotes: 3