Interface implementation question.

L

Larry

I checked definition of class CollectionBase

public abstract class CollectionBase : IList, ICollection,
IEnumerable, it implements 3 interface IList, ICollection and
IEnumerable.

I found IList is derived or extended from ICollection and
IEnumerable. Why the definition of class CollectionBase just implement
IList interface which has functions of ICollection and IEnumerable?

Thanks ahead.

Laurence
 
P

Peter Duniho

I checked definition of class CollectionBase

public abstract class CollectionBase : IList, ICollection,
IEnumerable, it implements 3 interface IList, ICollection and
IEnumerable.

I found IList is derived or extended from ICollection and
IEnumerable. Why the definition of class CollectionBase just implement
IList interface which has functions of ICollection and IEnumerable?

I'm not exactly clear on what your question is. That is, are you asking:

1) Why does the class CollectionBase *only* implement the IList
interface?

Or are you asking:

2) Why does the class CollectionBase inherit from all three interfaces
even though IList already inherits from ICollection and IEnumerable?

If #1, then the answer is simply that because of the inheritance, there's
no need to implement new methods for the other two interfaces.

If #2, then I don't actually know. I presume it's simply to make the
interfaces more explicit, so that the CollectionBase-derived classes are
guaranteed to still implement the other two base interfaces even if for
some reason IList is changed or removed. But frankly, it seems to me that
doing something like changing IList so that it no longer inherits from the
other two, or removing it from the CollectionBase class altogether would
be an egregious violation of the whole idea of publishing the interfaces
in the first place. Furthermore, if someone *did* make that sort of
change, it would be major enough that they could easily just add in the
two base interfaces after the fact; any caller who only cared about the
base interfaces would still work, and any caller trying to get the base
interfaces from the derived interface would have to be revisited anyway.

Of course, I could be missing something. Happens all the time. :) But I
don't see what the point of inheriting from both the derived interface,
and two base interfaces that derived interface inherits.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top