18
Asking myself again and again what good code is, I read the advice "Accept the weakest, return the strongest".
For me it is obvious why to accept the weakest: The method declares the weakest possible contract with its client. So the clients do not need to be "specialized" against a very "strong" interface.
"Return the strongest" is not that clear for me. Why should I return the strongest interface possible? What is the strongest interface? How do you quantify the strongness?
Assume there is a method returning a sequence of elements. The weakest interface would be of type IEnumerable. Following the guideline we should return someting like IList. But why?
I would like to ask for an explanation why to return the strongest interface.