I'm working on an API and one of my teammates insists that it is better to return Interfaces than returning concrete objects to the end user.
The problem is that as the API coding is ongoing the maintainability of the interfaces is getting troublesome, if we need to add something like a parameter to a method of the interface then we need to add it in the interface first, and then add that method on all the other classes that inherit from that interface.
That made us doubt of the benefit of having those interfaces vs their maintainability, is there really a good reason to expose only interfaces on an API?
"is there really a good reason to expose only interfaces on an API?"
Absolutely! Testability! For you, and for your consumers. They can mock your API to return mocks implementing your interfaces and test their code without having to run your API.
It also gives you a lot more flexibility in your implementation. By keeping your concrete classes out of the public eye, you're free to make changes rev-to-rev about what you actually return to satisfy the interface request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With