We define a public API as:
public
method in a class librarypublic class MyPublicService
{
public string DoWork(List<string> ss)
{
// we do not use any of List<T>'s methods...
return ss.FirstOrDefault()?.ToUpper() ?? "";
}
}
public class MyPublicService
{
// ...so let's accept an IEnumerable<T> instead to be nice to the client
public string DoWork(IEnumerable<string> ss)
{
return ss.FirstOrDefault()?.ToUpper() ?? "";
}
IEnumerable<T>
for collection- or sequence-like structures. It is immutable, and keeps the API implementation as flexible as possible.IEnumerable<T>
anyway.public class MyDto
{
public List<string> MyStrings;
}
public class MyDto
{
// now we are free to change the implementation to
// almost anything without breaking the client
public IEnumerable<string> MyStrings;
}