If I have an interface with a method that returns a collection of something, is it possible to return an implementation of the collection type instead?
For example:
public interface IVehicle
{
IEnumerable<Part> GetParts(int id);
}
public class Car : IVehicle
{
List<Part> GetParts(int id)
{
//return list of car parts
}
}
public class Train : IVehicle
{
IEnumerable<Part> GetParts(int id)
{
//return IEnumerable of train parts
}
}
If not, why not?
At least to me, this makes sense.