Java – using interfaces on the service layer
In our project architecture, we use the classic MVC pattern, including the classic service layer (open transaction and call Dao layer)
For each service, we have an implementation and its interface But to be honest, I'm pretty sure we'll never have multiple implementations for a service and its interface Well, perhaps more clearly, declaring public methods in the interface helps to know the role of services, but the interface is used for multiple implementations. If we know that we won't have multiple implementations, should we keep them?
Solution
From documentation:
If you know there is only one implementation, the implementation itself defines the contract, so you can delete the interface
However, writing interfaces can help you better define contracts, and you may need to write simulations for services at a given point, in which case you will benefit from the use of interfaces