Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a need to create Lists of several types of objects.
Each list object will have some things in common, so I thought create a base list class like so...

Public MustInherit Class BaseList
       Inherits List

Private _oParent as Object

Public Sub New(ByVal parent as Object)
     MyBase.New
     _oParent = parent
End Sub


And the consume the BaseList object like so..

Public Class People
     Inherits BaseList(Of Person)

End Class


What is not liked in the Inherits List is the BaseList object as it expects a Type.
How do I resolve this issue.

Thanks
Posted

Steven

have a look at this simple example I think it should give you an idea

VB
 Public Class Person

   Private _Name As String = String.Empty

   Public Property Name() As String
       Get
           Return _Name
       End Get
       Set(ByVal value As String)
           _Name = value
       End Set
   End Property
 End Class

Public Class Emplyoee
   Inherits Person

   Private _EmpID As Integer = 0

   Public Property EmployeeID() As Integer
       Get
           Return _EmpID
       End Get
       Set(ByVal value As Integer)
           _EmpId = value
       End Set
   End Property
 End Class


This would then be the variable you use to create the genric.list(of t) i.e. dim People as new list(of Employee).

This might also prove to be a good article it helped me get the basics of inheritance How to use inheritance in Visual Basic 2005 or in Visual Basic .NET[^]
 
Share this answer
 
v2
It looks like you have no idea of OOP. This is called polymorphism; and you should subclass not the container type (list), but the element type (person) and use either interfaces or late binding.

You code is beyond the fix. Through it out, take a book or a manual on language and .NET and start over. Down the road, pay attention at:

http://en.wikipedia.org/wiki/Oop[^],
http://en.wikipedia.org/wiki/Late_binding[^],
http://en.wikipedia.org/wiki/Dynamic_dispatch[^],
http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29[^],
http://en.wikipedia.org/wiki/Interface_%28object-oriented_programming%29[^].

—SA
 
Share this answer
 
v2
Comments
Abhinav S 6-Feb-12 10:48am    
My 5.
Sergey Alexandrovich Kryukov 6-Feb-12 10:51am    
Thank you, Abhinav.
--SA
Steven J Jowett 6-Feb-12 12:06pm    
I feel like I've just been flamed.
I think I understand OOP very well, it is obvious that I did not explain my problem so well.
The existing code is not beyond fix, as you suggested. It works, looking for a quicker/simpler way of adding additional functionality.

Thanks, but I not sure your reply deserves a 5
Sergey Alexandrovich Kryukov 6-Feb-12 14:11pm    
I only talk based in the impression based on your question and only in order to help you, as, in case I'm still right, you would need exactly my advice, not fixing of your code. You see, people deeply understanding OOP usually know how to design for such simple problems like yours. The solution is my second question.

"Understanding OOP very well", or anything at all, does not come through just declarations.

I could potentially flame only with someone who at argues with me at least with some opinion which could be interesting to me, so our discussion could not be a flame in principle.

However, I would be more happen to appear wrong here. Why talking about ambitions if we can talk about essential facts? Proof me wrong, that is.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900