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
22
u/EvaristeGalois11 Aug 23 '24
It's a relic from the past when proxying or mocking a concrete class wasn't possible.
Use interfaces only if you need interfaces. Don't clutter your code with useless noise.