Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

Help with inheritance problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 31 Jul 2007 18:12 GMT
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
won’t 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.