Home All Groups Group Topic Archive Search About

Generic Lists Desing Issue

Author
22 Mar 2006 10:01 AM
medo
Generic Lists are great!
But I think you missed a opportunity.

Here is my problem.
I made a Collection "Family: List<Person> "
which will contain 'Family'. I wanted to override the Add method so you can
only add persons whose Parents or Childeren are already in the list, but the
Add method is not virtual!

The Add method of Arraylist is virtual and I see no reason for the generic
counterpart not to be.

My work around is to create my own GenericList that has a private List<T>
and duplicate all IList<T> members and make them virtual, but still it
should have been there all along.

I see no reason why List<> or all other generic collections have no virtual
methods, is there? Maybe speed, but that wasn't an issue with ArrayList so
it shouldn't be with generic collections either.

Author
22 Mar 2006 10:08 AM
johan.appelgren@gmail.com
Take a look at System.Collections.ObjectModel.Collection<T>
<http://msdn2.microsoft.com/en-US/library/ms132397(VS.80).aspx>.
Author
22 Mar 2006 6:56 PM
Mattias Sjögren
>I see no reason why List<> or all other generic collections have no virtual
>methods, is there? Maybe speed, but that wasn't an issue with ArrayList so
>it shouldn't be with generic collections either.

Actually it was, or at least performance is one of the reasons the
List<T> methods are non-virtual. See this post for example

http://blogs.msdn.com/brada/archive/2004/04/25/120055.aspx


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

AddThis Social Bookmark Button