List<T> inheritance

  • Thread starter Thread starter Fabio Z
  • Start date Start date
"Fabio Z" <[email protected]> a écrit dans le message de (e-mail address removed)...

| If I should say it all, I should implement an interface, but not IList<T>,
| because I need a object that doesn't publish Add, Remove, Clear that are
| managed internally (I'm thinking about IEnumerable<T>).

If you don't want to publish those methods, then look at ICollection, the
non-generic interface. All the methods you want to hide are those that
belong to ICollection<T> so, by using the non-generic interface, you should
get what you need.

Joanna
 
"Joanna Carter [TeamB]" <[email protected]> ha scritto nel messaggio

If you don't want to publish those methods, then look at ICollection, the
non-generic interface. All the methods you want to hide are those that
belong to ICollection<T> so, by using the non-generic interface, you
should
get what you need.

You're right, but I'll loose the strong-typing :(
 
"Fabio" <[email protected]> a écrit dans le message de (e-mail address removed)...

| You're right, but I'll loose the strong-typing :(

Since ICollection doesn't expose any members that access the items in the
list, this is very "strongly typed" :-)

You are allowed to write your own interfaces you know :-) So, why don't you
derive your own interface from ICollection ?

Something like :

public IReadOnlyCollection<T> : ICollection
{
T this[int index] { get; set; }
}

Then you get to write a class that implements this interface like this :

public class ItemCollection<T> : IReadOnlyCollection<T> where T : Item
{
...
}

This will then also have to implement IEnumerable by inheritance.

Does this help ?

Joanna
 
Back
Top