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 202857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:19:36+00:00 2026-05-11T17:19:36+00:00

I have the following sample code in a VB.NET console application. It compiles and

  • 0

I have the following sample code in a VB.NET console application. It compiles and works, but feels like a hack. Is there a way to define EmptyChild so that it inherits from Intermediate(Of T As Class) without using the dummy EmptyClass?

Module Module1
Sub Main()

    Dim Child1 = New RealChild()
    Child1.Content = New RealClass()
    Dim Child2 = New EmptyChild()

    Console.WriteLine("RealChild says: " & Child1.Test)
    Console.WriteLine("EmptyChild says: " & Child2.Test)
    Console.ReadLine()
End Sub

Public Class EmptyClass

End Class

Public Class RealClass

    Public Overrides Function ToString() As String
        Return "This is the RealClass"
    End Function

End Class

Public MustInherit Class Base(Of T As Class)

    Private _content As T = Nothing
    Public Property Content() As T
        Get
            Return _content
        End Get
        Set(ByVal value As T)
            _content = value
        End Set
    End Property

    Public Overridable Function Test() As String
        If Me._content IsNot Nothing Then
            Return Me._content.ToString
        Else
            Return "Content not initialized."
        End If
    End Function

End Class

Public MustInherit Class Intermediate(Of T As Class)
    Inherits Base(Of T)

    'some methods/properties here needed by Child classes

End Class

Public Class RealChild
    Inherits Intermediate(Of RealClass)

    'This class needs all functionality from Intermediate.

End Class

Public Class EmptyChild
    Inherits Intermediate(Of EmptyClass)

    'This class needs some functionality from Intermediate,
    ' but not the Content as T property.

    Public Overrides Function Test() As String
        Return "We don't care about Content property or Type T here."
    End Function

End Class
End Module

The other way to do this would be to move the generic code out of the Base class and then create 2 Intermediate classes like this:

Public MustInherit Class Intermediate
    Inherits Base

    'some methods/properties here needed by Child classes

End Class

Public MustInherit Class Intermediate(Of T As Class)
    Inherits Intermediate

    'implement generic Content property here

End Class

Then RealChild would inherit from the generic Intermediate and EmptyChild would inherit from the non-generic Intermediate. My problem with that solution is that the Base class is in a separate assembly and I need to keep the code that handles the generic type in that assembly. And there is functionality in the Intermediate class that does not belong in the assembly with the Base 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-05-11T17:19:37+00:00Added an answer on May 11, 2026 at 5:19 pm

    Yes, you need to specify a type parameter when you inherit, or your EmptyChild must be generic as well. But, you don’t have to dummy up a EmptyClass – just use Object as your type parameter:

     Public Class EmptyClass
        Inherits Intermediate(Of Object)
     End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 103k
  • Answers 103k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Java generics are so different from C++ templates that I… May 11, 2026 at 8:22 pm
  • Editorial Team
    Editorial Team added an answer It can be done by: Handling the ButtonPressEvent of the… May 11, 2026 at 8:22 pm
  • Editorial Team
    Editorial Team added an answer First step: install Firebug for Firefox. There are three connected… May 11, 2026 at 8:22 pm

Related Questions

How much code documentation in your .NET source is too much? Some background: I
The following code for a co-worker throws the following error when he tries to
Yes, there is a similar question here . However, that question doesn't seem to
I have a bunch of simple lookup tables cached in my asp.net application since
It seems like when you have a WinForms .NET application, and a ComboBox (set

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.