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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:02:33+00:00 2026-05-11T06:02:33+00:00

I have a function which I need to call for three different types, with

  • 0

I have a function which I need to call for three different types, with the underlying logic remaining the same for all the different types, so I figured it would be best to write this function using generics.

Here is the basic outline of the classes and functions involved:

'PO Base class' Public MustInherit Class ProductionOrder      Public MustInherit Class Collection(Of T)           Inherits System.Collections.Generic.Dictionary(Of Long, T)      End Class      '....' End Class  Public Class ProfileProductionOrder      Inherits ProductionOrder      Public Class Collection           Inherits ProductionOrder.Collection(Of ProfileProductionOrder)      End Class      '....' End Class  Public Class UnitProductionOrder      Inherits ProductionOrder      Public Class Collection           Inherits ProductionOrder.Collection(Of UnitProductionOrder)      End Class      '....' End Class  Public Class CrateProductionOrder      Inherits ProductionOrder      Public Class Collection           Inherits ProductionOrder.Collection(Of CrateProductionOrder)      End Class      '....' End Class  'Generic function, intended to work on profile, unit, and crate production orders.' 'This method resides in the base class of the GUI.' Protected Sub FillPOCells(Of T As ProductionOrder.Collection(Of ProductionOrder)) _     (ByVal dgv As DataGridView, ByVal ProductionOrders As T)      '...do some stuff' End Sub  'This function resides in the Profile child GUI class.' Protected Sub LoadDataGridViewPOs()      Dim dgv As DataGridView      Dim ProductionOrders As ProfileProductionOrder.Collection      '....'      'Fill PO Cells'      FillPOCells(Of ProfileProductionOrder.Collection)(dgv, ProductionOrders)      '....' End Sub 

The ProductionOrder base and child classes compile, as does the FillPOCells function. But when I call FillPOCells inside LoadDataGridViewPOs the compiler complains that ‘Type argument ‘ProfileProductionOrder.Collection’ does not inherit from or implement the constraint type ‘ProductionOrder.Collection(Of ProductionOrder)’.

Also, here is some explanation about why things are set up this way. My predecessor set up the convention of putting the collection of an object as a subclass within it, so it’s easy to refer to it as Obj.Collection. Next, the reason we need three different types of production orders is because they are treated differently and stored in different tables and such on the back end. Lastly, I realize I could implement this fairly easily without getting this particular generic function to work, but I’m looking at this as a learning experience to improve my understanding of generics and OO design.

So the question is, why am I getting that compiler error and how should I change my class and generics design to accomplish what I have in mind?

If you need any further explanation about what I’m trying to do or how I have things set up let me know. The main idea is to have a function that can take a collection who’s elements belong to one of the ProductionOrder child classes, and run operations on these elements that only use the functionality held in their ProductionOrder base class (hence why either of the child types is okay to operate on in the function).

  • 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. 2026-05-11T06:02:34+00:00Added an answer on May 11, 2026 at 6:02 am
    'PO Base class' Public MustInherit Class ProductionOrder(Of T)      Public MustInherit Class Collection           Inherits System.Collections.Generic.Dictionary(Of Long, T)      End Class      '....' End Class  Public Class ProfileProductionOrder      Inherits ProductionOrder(Of ProfileProductionOrder)      '....' End Class  Public Class UnitProductionOrder      Inherits ProductionOrder(Of UnitProductionOrder)      '....' End Class  Public Class CrateProductionOrder      Inherits ProductionOrder(Of CrateProductionOrder)      '....' End Class 

    That is a lot simpler according to me. But I higly doubt you need the CollectionClass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should be able to include a close form tag… May 12, 2026 at 3:56 pm
  • Editorial Team
    Editorial Team added an answer Try this: import math def format_percentage(x, precision=3): return ("%%.%df%%%%" %… May 12, 2026 at 3:56 pm
  • Editorial Team
    Editorial Team added an answer If I understand your question correctly (and perhaps I don't),… May 12, 2026 at 3:56 pm

Related Questions

I have a function which needs to be invoked with a different number of
I have a worker thread that is listening to a TCP socket for incoming
I want to have/define a unique id for each data row in my Excel
First of all I have to admit that my programming skills are pretty limited

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.