0

I have used Service interface for ServiceImpl class in some projects and last week I watched a video where it is said that "there is no need to use interface anymore. Spring Boot provide injection and just create ServiceImpl class, no need to create Service interface.

However, I am confused, is that true for Spring Boot project that we just need ServiceImpl class, and no need to use Service interface? Any idea?

  • This may turn out to be an opinionated answer, but AFAIK using an interface was never required. To me, the decision to use an interface is mostly based on this question: Are there multiple implementations? If yes, then use interface. If no, then there's usually no need for an interface. In the example, `ServiceImpl` as a class name tells the reader nothing about the specific implementation, so an interface adds an unnecessary level of abstraction. – Andrew S Mar 09 '22 at 18:23
  • Maybe, but when I look at the answers, I am getting much more confused. Then what is short answer? As far as I see, for multiple implementation it is a need. Otherwise, in most situations no need. What do you think? –  Mar 09 '22 at 18:24
  • @AndrewS Yes, I also pointed that issue before reading your comment. But if I will need in the future then I think it is good idea to start the project with interface. Otherwise it would be much more harder to update the project later so that implement interfaces for each services in the project. any idea? –  Mar 09 '22 at 18:26
  • _But if I will need in the future_ Modern IDEs make re-factoring easy. Over-engineering a solution now, for a future requirement that might never actually exist, adds unnecessary complexity and is a waste of time. – Andrew S Mar 09 '22 at 18:32

0 Answers0