What is the difference between Data Access Objects (DAO) and Repository patterns? I am developing an application using Enterprise Java Beans (EJB3), Hibernate ORM as infrastructure, and Domain-Driven Design (DDD) and Test-Driven Development (TDD) as design techniques.
What is the difference between Data Access Objects (DAO) and Repository patterns? I am
Share
DAOis an abstraction of data persistence.Repositoryis an abstraction of a collection of objects.DAOwould be considered closer to the database, often table-centric.Repositorywould be considered closer to the Domain, dealing only in Aggregate Roots.Repositorycould be implemented usingDAO‘s, but you wouldn’t do the opposite.Also, a
Repositoryis generally a narrower interface. It should be simply a collection of objects, with aGet(id),Find(ISpecification),Add(Entity).A method like
Updateis appropriate on aDAO, but not aRepository– when using aRepository, changes to entities would usually be tracked by separate UnitOfWork.It does seem common to see implementations called a
Repositorythat is really more of aDAO, and hence I think there is some confusion about the difference between them.