<
[email protected]> a écrit dans le message de (e-mail address removed)...
| The way I see interface is that it is a synonym for a "contract"
Agreed
| So, following that notion of contract, i see no reason why a IList<T>
| contract does not fullfill a IList contract.
MY thought is that the hierarchies, non-generic and generic are split
differently and could not be reconciled because it would break backwards
compatibility.
public interface ICollection : IEnumerable
{
int Count { get; }
bool IsSynchronized { get; }
object SyncRoot { get; }
void CopyTo(Array array, int index);
}
public interface IList : ICollection, IEnumerable
{
bool IsFixedSize { get; }
bool IsReadOnly { get; }
object this[int index] { get; set; }
int Add(object value);
void Clear();
bool Contains(object value);
int IndexOf(object value);
void Insert(int index, object value);
void Remove(object value);
void RemoveAt(int index);
}
public interface ICollection<T> : IEnumerable<T>, IEnumerable
{
int Count { get; }
bool IsReadOnly { get; }
void Add(T item);
void Clear();
bool Contains(T item);
void CopyTo(T[] array, int arrayIndex);
bool Remove(T item);
}
public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
{
T this[int index] { get; set; }
int IndexOf(T item);
void Insert(int index, T item);
void RemoveAt(int index);
}
As you can see, the members of IList<T> are not just typesafe equivalents of
IList, the members are split differently between ICollection and IList.
The question would be raised, which is the bettter split of functionality ?
One other point : why do the List interfaces inherit from IEnumerable again,
when inheriting from ICollection would already give this functionality.
Joanna