I have several classes that will have a property of type List (of
whatever).
For example, I will have collections named:
Protocols that will have a property named Items as List (of Protocol).
Orders that will have a property named Items as List (of Order).
Etc.
All this classes will have their own Add, Remove, Count, etc, method.
So for example, the Add method of the orders class will be as follows:
Public sub Add(NewOrder as Order)
Me.m_Items.Add(NewOrder)
End Sub
It is very repetitive to create and Add, Remove, etc, method for every
class that will implement this functionality, so I thought about
creating a base class named SpecializedCollectionBase that will contain
an Add, Remove, etc method, and the rest of the classes can inherit from
it.
The only problem that I see with this is that SpecializedCollectionBase
wont know of what type is the Items property of the class that is
inheriting.
It can be of Order, of Protocol, etc.
I hope you understand my point and can help me to make this more
efficient.
Thanks
Kerry Moorman - 31 Jul 2007 18:22 GMT
Mike,
Why not have each collection inherit from List:
Public Class Protocols
Inherits List (Of Protocol)
Then add any specific collection methods to the Protocols class, etc.
Kerry Moorman
> I have several classes that will have a property of type List (of
> whatever).
[quoted text clipped - 33 lines]
>
> Thanks
Herfried K. Wagner [MVP] - 31 Jul 2007 21:22 GMT
"Kerry Moorman" <KerryMoorman@discussions.microsoft.com> schrieb:
> Why not have each collection inherit from List:
>
> Public Class Protocols
> Inherits List (Of Protocol)
>
> Then add any specific collection methods to the Protocols class, etc.
Maybe 'System.Collections.ObjectModel.Collection(Of T)' is more suitable
than 'List(Of T)'.

Signature
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jack Jackson - 31 Jul 2007 18:29 GMT
Take a look at Generics.
>I have several classes that will have a property of type List (of
>whatever).
[quoted text clipped - 33 lines]
>
>Thanks
Armin Zingler - 31 Jul 2007 18:39 GMT
> I have several classes that will have a property of type List (of
> whatever).
[quoted text clipped - 35 lines]
>
> Thanks
I don't see why you need such a class at all. The List(Of) class already has
Add/Remove/Count members.
You could directly inherit from List(Of)
class Orders
inherits list(Of Order)
end class
class Protocols
inherits list(Of Protocol)
end class
...
dim o as new orders
dim p as new protocols
Armin