Hi there Spring/SpringBoot fans/experts,
Hope you’re doing well. I’ve been grappling with this question for a while now, and I thought I’d ask a spring/springboot expert for their opinion and experience on it. It’s about interface as it relates to its usage in springboot.
First of all let me say this; from a Java or software engineering stand point, I understand and am well aware of the use or purpose of interfaces, they are contracts.
So, from springboot as a FRAMEWORK/library standpoint, it make sense in the framework source code.
Now, from springboot as an APPLICATION I’ve seen cases where every service class (@Service) has a corresponding interface :
public interface MyService {}
public class MyServiceImpl implement MyService {}
99.99% of the time, these interfaces never get implemented by anything else ever. Why has this become such a popular thing to do in springboot, where every single service class has a corresponding interface even though nothing else will ever implement these interfaces?
To me it seems to create more complexity and code to maintain with no apparent benefits. Note that I’m strictly referring to @Service
class interfaces only.
Is it good practice to do that? Is there something I’m missing here. What’s your experience and thoughts on this please?
Thank you in advance!