Sunday, 15 March 2015

c# - Should I expose interfaces instead of concrete Objects on my API? -


I am working on an API and one of my teammates says that the interfaces compared to returning concrete objects It is better to get back the end user.

The problem is that API coding is going on, maintenance of the interface is having trouble, if we have to add some method of the interface as a parameter, then we need to add it first in the interface, and then the method Add all other classes to that interface.

Due to this we have doubts about the benefits of maintaining those interfaces, but in reality is this a good reason to expose the interface to the API only?

"Is there really a good reason to just expose the interface to an API?"

Absolutely! Testability! For you and your consumers, they can duplicate your API to implement your interface without testing your API and test your code for your API.

It also gives you more flexibility in your implementation. By placing your concrete sections out of the public eye, you are free to amend the amendments about exactly what you return to satisfy the interface request.


No comments:

Post a Comment