In the article Don’t use DAO, use Repository there is a pretty good explanation of the differences between DAO and repository patterns.
My brief retelling - DAO makes us to bloat interface with multiple methods, which obstruct changes and testing. In turn, repository encapsulate all customizations/changes with query method, which accept Specification as an argument. When you need a new behavior at repository - you shouldn't change it, instead create a new heir of Specification.
My conslusion - repository pattern is better than DAO due its interfaces are closed to modification.
Am I right so far? Haven't I missed some benefits of repository pattern?
BUT, if you'd look at Spring's accessing data JPA guide, you'll find the next code:
public interface CustomerRepository extends CrudRepository<Customer, Long> {
List<Customer> findByLastName(String lastName);
//...
}
Doesn't it conflict with the previous article? Why Spring's repository force us to add new methods to interface?
Aucun commentaire:
Enregistrer un commentaire