In .NET 4.5 / C# 5, IReadOnlyCollection<T>
is declared with a Count
property:
public interface IReadOnlyCollection<out T> : IEnumerable<T>, IEnumerable
{
int Count { get; }
}
I am wondering, wouldn't it have made sense for ICollection<T>
to implement the IReadOnlyCollection<T>
interface as well:
public interface ICollection<T> : IEnumerable<T>, IEnumerable, *IReadOnlyCollection<T>*
This would've meant that classes implementing ICollection<T>
would've automatically implemented IReadOnlyCollection<T>
. This sounds reasonable to me.
The ICollection<T>
abstraction can be viewed as an extension of the IReadOnlyCollection<T>
abstraction. Note that List<T>
, for example, implements both ICollection<T>
and IReadOnlyCollection<T>
.
However it has not been designed that way.
What am I missing here? Why would the current implementation have been chosen instead?
UPDATE
I'm looking for an answer that uses Object Oriented design reasoning to explain why:
- A concrete class such as
List<T>
implementing bothIReadOnlyCollection<T>
andICollection<T>
is a better design than:
ICollection<T>
implementingIReadOnlyCollection<T>
directly
Also please note that this is essentially the same question as:
- Why doesn't
IList<T>
implementIReadOnlyList<T>
? - Why doesn't
IDictionary<T>
implementIReadOnlyDictionary<T>
?