17

I'm trying to design an rest API in spring boot and what to ask about a few design decisions. I am completely confused by the whole difference between DAO vs Repository pattern/design. After hours of reading I still don't really understand the difference between the two or which one is preferred standard for designing API's that make backend connections.

Here's a simply UML diagram to highlight the high level view of the api: enter image description here

This is how I understand a good architecture of an API. But then I came across this article using repository pattern instead of dao with a specification design. I don't understand why a dao interface can't just have a query function? Does that break the idea of what a DAO is or something?

My question is: what's the best standard to use in today's day in developing an API in Spring Boot and Java 8

Richard
  • 5,840
  • 36
  • 123
  • 208
  • You have several questions in here that might have concise answers, but your overall question might be a bit broad for SO and attract opinionated answers. As such, it probably doesn't belong here. – rmlan Apr 27 '17 at 16:25
  • this might be a duplicate of http://stackoverflow.com/q/8550124/1490322 – Jose Martinez Apr 27 '17 at 16:34
  • Possible duplicate of [What is the difference between DAO and Repository patterns?](http://stackoverflow.com/questions/8550124/what-is-the-difference-between-dao-and-repository-patterns) – Jose Martinez Apr 27 '17 at 16:35
  • Dao == Repository AFAIK in terms of Spring repositories – EpicPandaForce Apr 27 '17 at 16:49

1 Answers1

6

If I understood correctly your question, the whole point of using Spring Service/Repository is to separate the business logic from the Controller to the Service class, and the only thing the Repository will do is DB operations, and you will inject it in your Service. There is no difference between DAO (assuming your DAO is a bunch of code using JPA) and Repository, but with Spring Repository you can use Query Methods, which is awesome!

Any suggestion, feel free!

Mateus Luiz
  • 756
  • 7
  • 20
  • but why can't you just use a query method inside of a DAO? I guess I'm just not getting it fully without seeing a good example. Is there anything out there that I can look at that uses both a repository and dao layer. Because [this post](http://stackoverflow.com/questions/8550124/what-is-the-difference-between-dao-and-repository-patterns) highlights that there is indeed a big difference between the two – Richard Apr 27 '17 at 18:04
  • 1
    Because to use Query Methods you need do extend the Spring classes, here's the documentation for Spring Data JPA: http://docs.spring.io/spring-data/jpa/docs/1.11.3.RELEASE/reference/html/ – Mateus Luiz Apr 28 '17 at 18:15