r/SpringBoot • u/BluePillOverRedPill • Aug 23 '24
Interface for each service?
Hi Everyone!
I’m a bit confused about the use of interfaces for all services in Spring Boot. I understand that interfaces serve as a contract and offer benefits like easier testing and flexibility for future changes. However, I’ve also read that if you’re not planning to have multiple implementations of a service, using interfaces might be unnecessary. Could you clarify the best practices for using interfaces in this context, and explain how they impact dependency injection and testing?
24
Upvotes
1
u/drazon2016 Aug 24 '24
You are right! No need of interfaces unless you have multiple implementation or exposing the code as a library to internal teams!
I seen some people define it in the name of following OOPs.. don’t fall for it