JohnB
JohnB

Reputation: 1793

VB.NET Abstract Property

I have an abstract "GridBase" class with two types of derived classes "DetailGrid" and "HeaderGrid".

Respectively, one is comprised of "DetailRow" objects and the other "HeaderRow" objects. Both of those inherit from a "RowBase" abstract class.

What I am trying to do is the following:

Public MustInherit Class GridBase
    Private pRows As List(Of RowBase)

    Public ReadOnly Property Rows As List(Of RowBase)
        Get
            Return pRows
        End Get
    End Property
End Class

Public Class DetailGrid
    Inherits GridBase
End Class

In this scenario, I want DetailGrid.Rows to return a list of DetailRow. I want HeaderRow.Rows to return a list of HeaderRow. Am I on the right track with this or should the Rows property not be included in the GridBase class?

Upvotes: 2

Views: 1801

Answers (1)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239724

If you want a stronger typing guarantee, then you probably want:

Public MustInherit Class GridBase(Of T as RowBase)
    Private pRows As List(Of T)

    Public ReadOnly Property Rows As List(Of T)
        Get
            Return pRows
        End Get
    End Property
End Class

Public Class DetailGrid
    Inherits GridBase(Of DetailRow)
End Class

Upvotes: 3

Related Questions