| Thanks !
|
| It works ! but I think yielding the elements will be more expensive
| than using System.Collections.IEnumerator and casting to IPerson, from
| a performance standpoint.
As I showed in the second example, you don't even need to write a separate
enumerator, you can just do a foreach on a List<Friend> asking for the
element as IPerson and it will work.
| 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.
| Now I need these collections to show certain behavior and present
| themselves thorough an interfase named IGroupOfPeople, like:
[quoted text clipped - 7 lines]
| 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.
| Maybe is better to modify the interfase to :
|
[quoted text clipped - 6 lines]
| And let the users of the collection the casting from System.Object to
| IPerson.
Not a good idea; this is just what generic classes seek to eliminate.
Joanna

Signature
Joanna Carter [TeamB]
Consultant Software Engineer
Daniel - 01 Jul 2006 21:38 GMT
> | I have several collections like Friends: Men (collection of
> | Man:IPerson), Women (collection of Woman:IPerson), Artists (collection
[quoted text clipped - 6 lines]
> 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>
> | Now I need these collections to show certain behavior and present
> | themselves thorough an interfase named IGroupOfPeople, like:
[quoted text clipped - 10 lines]
> 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