Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7785357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:14:33+00:00 2026-06-01T20:14:33+00:00

I have two Parser classes that inherit from a base class, BaseParser. I want

  • 0

I have two Parser classes that inherit from a base class, BaseParser. I want to use either class as a parameter in another Monitor class. The Parser classes, CS600 and TCH600, both have two properties, RawDataList and SummaryDataList. The CS600 class’s RawDataList returns a List(of CS600Data); the TCH600 RawDataList returns a List(of TCH600Data). The SummaryDataList returns similar classes in each Parser class. CS600Data and TCH600Data derive from a base class, BaseData.
BaseParser also has RawDataList (List(of BaseData)) and SummaryDataList (List(of BaseSummaryData))

The Monitor class has a private field, _thisParser which can be either of the two concrete Parsers above. I want to be able to call and use RawDataList and SummaryDataList of _thisParser within Monitor class, but when I construct the concrete Parser classes, Visual Studio notes that the RawDataList property of CS600 cannot override the RawDataList property of the BaseParser because they differ in their return types.

I thought that since CS600Data derived from BaseData (but also adds some new properties of its own) that I could use CS600Data wherever I use BaseData. What am I misunderstanding? How can I correctly construct these classes?

Public MustInherit Class BaseParser

    Protected _rawDataList As List(Of RawGasData.BaseData)
    Public MustOverride ReadOnly Property RawDataList() As List(Of RawGasData.BaseData)

    Protected _summaryDataList As List(Of SummaryGasData.BaseSummaryData)
    Public MustOverride ReadOnly Property SummaryDataList() As List(Of SummaryGasData.BaseSummaryData)

    Public Event GasDataCreated(ByVal sender As Object, ByVal e As EventArgs)

    Public Sub New()
    End Sub

    Public Sub New(ByVal dataFilePath As String, ByVal unit As String)
        Load(dataFilePath, unit)
    End Sub

    Public Sub Load(ByVal dataFilePath As String, ByVal unit As String)
        Dim contents = My.Computer.FileSystem.ReadAllText(dataFilePath)
        ParseRawData(contents)
        GenerateSummaryData(contents, unit)
        RaiseEvent GasDataCreated(Me, EventArgs.Empty)
    End Sub

    Protected MustOverride Sub ParseRawData(ByVal fileContents As String)

    Protected MustOverride Sub GenerateSummaryData(ByVal fileContents As String, ByVal unit As String)

End Class

Public Class CS600Parser
    Inherits BaseParser

    Shadows _rawDataList As List(Of RawGasData.CS600Data)
    'Cannot override base class' RawDataList - differ by their return types
    Public Overrides ReadOnly Property RawDataList() As List(Of RawGasData.CS600Data)
        Get
            Return _rawDataList
        End Get
    End Property

    Shadows _summaryDataList As List(Of SummaryGasData.CS600SummaryData)
    'Cannot override base class' SummaryDataList - differ by their return types
    Public Overrides ReadOnly Property SummaryDataList() As List(Of SummaryGasData.CS600SummaryData)
        Get
            Return _summaryDataList
        End Get
    End Property

    Protected Overrides Sub ParseRawData(ByVal fileContents As String)
        Dim data = From d In fileContents.Trim.Split(CChar(vbCrLf)) _
                   Let fields = d.Split(","c).Select(Function(s) s.Trim) _
                   Select New RawGasData.CS600Data With { _
                        .SampleNumber = fields(0), _
                        .UserID = fields(1), _
                        .CarbonValue = CDbl(fields(2)), _
                        .SulfurValue = CDbl(fields(3))}

        _rawDataList = data.ToList

    End Sub

    Protected Overrides Sub GenerateSummaryData(ByVal fileContents As String, ByVal unit As String)
        Dim groupedData = From d In _rawDataList _
                          Group By d.SampleNumber Into Group _
                          Select New SummaryGasData.CS600SummaryData With { _
                            .DataTimeStamp = Now, _
                            .SampleNumber = SampleNumber, _
                            .UserID = Group.First.UserID, _
                            .CarbonAverage = Group.Select(Function(s) s.CarbonValue).Average, _
                            .CarbonUnit = unit, _
                            .SulfurAverage = Group.Select(Function(s) s.SulfurValue).Average, _
                            .SulfurUnit = unit}

        _summaryDataList = groupedData.ToList

    End Sub

End Class

Public Class TCHParser
    Inherits BaseParser

    Shadows _rawDataList As List(Of RawGasData.TCH600Data)
    'Cannot override base class' RawDataList - differ by their return types
    Public Overrides ReadOnly Property RawDataList() As List(Of RawGasData.TCH600Data)
        Get
            Return _rawDataList
        End Get
    End Property

    Shadows _summaryDataList As List(Of SummaryGasData.TCH600SummaryData)
    'Cannot override base class' SummaryDataList - differ by their return types
    Public Overrides ReadOnly Property SummaryDataList() As List(Of SummaryGasData.TCH600SummaryData)
        Get
            Return _summaryDataList
        End Get
    End Property

    Protected Overrides Sub ParseRawData(ByVal fileContents As String)
        Dim data = From d In fileContents.Trim.Split(CChar(vbCrLf)) _
       Let fields = d.Split(","c).Select(Function(s) s.Trim) _
       Select New RawGasData.TCH600Data With { _
            .SampleNumber = fields(0), _
            .UserID = fields(1), _
            .OxygenValue = CDbl(fields(2)), _
            .NitrogenValue = CDbl(fields(3)), _
            .HydrogenValue = CDbl(fields(4)), _
            .MassUsed = CDbl(fields(5))}

        _rawDataList = data.ToList

    End Sub

    Protected Overrides Sub GenerateSummaryData(ByVal fileContents As String, ByVal unit As String)
        Dim groupedData = From d In _rawDataList _
                          Group By d.SampleNumber Into Group _
                          Select New SummaryGasData.TCH600SummaryData With { _
                            .DataTimeStamp = Now, _
                            .SampleNumber = SampleNumber, _
                            .UserID = Group.First.UserID, _
                            .OxygenAverage = Group.Select(Function(s) s.OxygenValue).Average, _
                            .OxygenUnit = unit, _
                            .NitrogenAverage = Group.Select(Function(s) s.NitrogenValue).Average, _
                            .NitrogenUnit = unit, _
                            .HydrogenAverage = Group.Select(Function(s) s.HydrogenValue).Average, _
                            .HydrogenUnit = unit}

        _summaryDataList = groupedData.ToList
    End Sub


End Class


 Public MustInherit Class BaseData
    Implements IGasData

    Private _massUsed As Double
    Public Property MassUsed() As Double Implements IGasData.MassUsed
        Get
            Return _massUsed
        End Get
        Set(ByVal value As Double)
            _massUsed = value
        End Set
    End Property

    Private _sampleNumber As String
    Public Property SampleNumber() As String Implements IGasData.SampleNumber
        Get
            Return _sampleNumber
        End Get
        Set(ByVal value As String)
            _sampleNumber = value
        End Set
    End Property

    Private _userID As String
    Public Property UserID() As String Implements IGasData.UserID
        Get
            Return _userID
        End Get
        Set(ByVal value As String)
            _userID = value
        End Set
    End Property
End Class

Public Class CS600Data
    Inherits BaseData


    Private _carbonValue As Double
    Public Property CarbonValue() As Double
        Get
            Return _carbonValue
        End Get
        Set(ByVal value As Double)
            _carbonValue = value
        End Set
    End Property


    Private _sulfurValue As Double
    Public Property SulfurValue() As Double
        Get
            Return _sulfurValue
        End Get
        Set(ByVal value As Double)
            _sulfurValue = value
        End Set
    End Property

End Class

Public Class TCH600Data
    Inherits BaseData

    Private _oxygenValue As Double
    Public Property OxygenValue() As Double
        Get
            Return _oxygenValue
        End Get
        Set(ByVal value As Double)
            _oxygenValue = value
        End Set
    End Property


    Private _nitrogenValue As Double
    Public Property NitrogenValue() As Double
        Get
            Return _nitrogenValue
        End Get
        Set(ByVal value As Double)
            _nitrogenValue = value
        End Set
    End Property


    Private _hydrogenValue As Double
    Public Property HydrogenValue() As Double
        Get
            Return _hydrogenValue
        End Get
        Set(ByVal value As Double)
            _hydrogenValue = value
        End Set
    End Property

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:14:35+00:00Added an answer on June 1, 2026 at 8:14 pm

    Your overridden list properties, such as RawDataList, should be the type of the abstract base class (or better yet IGasData), and not the derived class for polymorphism to work. If you find that making the lists of type BaseData or IGasData is causing problems, you might want to check if your design adheres to the Liskov Substitution Principle.

    A simplified illustration which compiles and runs just fine (VB.Net 2010):

    Sub Main    
        Dim parser As BaseParser = New TCHParser()
        Console.WriteLine(parser)   
    End Sub
    
    Public MustInherit Class BaseData    
        Public Property SampleNumber() As String
    End Class
    
    Public Class TCH600Data 
        Inherits BaseData
    
        Public Property OxygenValue() As Double
    End Class
    
    Public MustInherit Class BaseParser
        Public MustOverride ReadOnly Property RawDataList As List(of BaseData)
    End Class
    

    TCHParser works just fine overriding the RawDataList property. Also, I’m not sure why the abstract base class had a Protected _rawDataList field. Remove it and you no longer have to worry about shadowing that field in derived types.

    Public Class TCHParser 
        Inherits BaseParser
    
        ' Populate the list just so we can test easily.
        Public Sub New()
            Dim data As New List(Of BaseData)
            data.Add(New TCH600Data With {
                .SampleNumber = "1", _
                .OxygenValue = 1.5d })
    
            data.Add(New TCH600Data With {
                .SampleNumber = "2", _
                .OxygenValue = 2.5d })
    
            _rawDataList = data
        End Sub
    
        Private _rawDataList As List(of BaseData)  
        Public Overrides ReadOnly Property RawDataList As List(of BaseData)
            Get
                Return _rawDataList
            End Get
        End Property
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes generated by LINQ2SQL both from the same table so they
I have these two classes: class Student { String name; String age ; }
Actually I have two java classes of which one is an activity class. Now
What I'm trying to do is fairly simple. I have two classes: public class
I have two classes, one of them is a configuration class. Inside of this
I want to parse a large XML file and I have two options: Perl
I have two application that need to talk to each other. App1 needs to
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have two stored procedures I wish to use in my stored procedure, but
I have the following classes: Defect - represents a type of data that can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.