[quoted text, click to view] >
> | I have several collections like Friends: Men (collection of
> | Man:IPerson), Women (collection of Woman:IPerson), Artists (collection
> | of Artist:IPerson), and so on; all of them derive from
> | ReadOnlyCollection<T>
>
>
> Why are you deriving from ReadOnlyCollection<T> ? It is only a read-only
> wrapper class that has to take a list that implements IList<T>. Unless you
> are planning on adding extra list functionality, there really is no need to
> derive from generic list classes; all you need is usually in the class as it
> stands.
>
Deriving from ReadOnlyCollection was based on the prospective use of
the collections: they populate themselves (from the data tier) and
should be ReadOnly fpr their consumers, that's the reason for using the
wrapper instead of IList<T>
[quoted text, click to view] > | Now I need these collections to show certain behavior and present
> | themselves thorough an interfase named IGroupOfPeople, like:
> |
> | interfase IGroupOfPeople: IEnumerable<IPerson>
> | {
> | void SayHi();
> | int AverageHeight {get;}
> | }
> |
> | now, the collections will implement the interfase IGroupOfPeople, and
> | therefore they must provide the GetEnumerator<IPerson>.
>
> This is bad design. You should keep the IEnumerable behaviour separate from
> any "group" behaviour.
>
I don't understand where is the "badness": consumers accessing objects
that implement IGroupOfPeople will be only interested in enumerating
its members (IPersons), I thought that the cleanest way is to just
expose the IEnumerable<IPerson> interfase, is there a better way?
Daniel