E
Etienne-Louis Nicolet
I try to figure out how to solve the following problem:
- I'd like to create an abstract class which should serve as base class for
various collections (lets call it 'MyCollection').
- All these collections contain items which inherit from the an abstract
class (e.g. 'MyClass'). The constructor of MyClass requires parameters.
- In either the constructor or a method in MyCollection I'd like to put the
code to add the items to to collection - something like 'Me.Add(New
MyClass(...))'. But since abstract classes can not be instantiated, how
would I have to code it?
Public MustInherit Class MyClass(Of TDataRow As DataRow)
Protected Sub New(pDataRow As TDataRow)
....
End Sub
End Class
Now I'd like to create another abstract class which inherits from MyClass as
follows:
Public MustInherit Class MyCollection(Of TDataRow As DataRow)
Inherits List(Of MyClass(Of TDataRow))
Protected Sub New(...)
' **********
' Here's the problem: The derived class should add instances
' of classes inherited from MyClass
' It should look something like
' **********
[Loop]
Me.Add(New MyClass(Of TDataRow)(pDataRow))
[End Loop]
End Sub
End Class
Many thanks for any suggestions,
Etienne
- I'd like to create an abstract class which should serve as base class for
various collections (lets call it 'MyCollection').
- All these collections contain items which inherit from the an abstract
class (e.g. 'MyClass'). The constructor of MyClass requires parameters.
- In either the constructor or a method in MyCollection I'd like to put the
code to add the items to to collection - something like 'Me.Add(New
MyClass(...))'. But since abstract classes can not be instantiated, how
would I have to code it?
Public MustInherit Class MyClass(Of TDataRow As DataRow)
Protected Sub New(pDataRow As TDataRow)
....
End Sub
End Class
Now I'd like to create another abstract class which inherits from MyClass as
follows:
Public MustInherit Class MyCollection(Of TDataRow As DataRow)
Inherits List(Of MyClass(Of TDataRow))
Protected Sub New(...)
' **********
' Here's the problem: The derived class should add instances
' of classes inherited from MyClass
' It should look something like
' **********
[Loop]
Me.Add(New MyClass(Of TDataRow)(pDataRow))
[End Loop]
End Sub
End Class
Many thanks for any suggestions,
Etienne