OOP related instantiation issue

CodeLiftsleep

Member
Joined
Mar 11, 2016
Messages
20
Programming Experience
3-5
Working on a football game and I have the following classes for Generation of players, coaches, etc.

Person which contains child classes Personnel and Players, and then Coaches and scouts which are child classes of personnel. Here is the issue I have. Inheritence is set up properly

I would like to have one call to generate whatever sub class of person type I am using, where I provide an Enum or string to Person's sub New and have it locate the correct type of person to create.

The issue is I am calling it from the main project but the instantiation isn't recognized from there in the Generation project. I don't want a bunch of code in the main project, I want it to remain clean and have all that extra code remain in the Generation Class. Another issue is that it needs to generate the number of these people/sub people passed in so I am declaring it as an array as in Public MyPerson() as Person, then having to instantiate each one.

Any help would be appreciated.
 
Person which contains child classes Personnel and Players, and then Coaches and scouts which are child classes of personnel.

This seems wrong. Normally what you want here is not nested types, but a base type and derived types.

Public Class Person
   ...
End Class

Public Class Personnel
    Inherits Person
   ...
   ' Additional members to the ones already defined in the Person base class here
End Class

Public Class Player
    Inherits Person
   ...
   ' Different additional members here, but still supplemental to the Person base class.
End Class

Public Class Coach
    Inherits Personnel
   ...
   ' Has all the members of personnel and then some.
End Class


You really need to post some of your code if you want help, I can only try to guess what exactly you mean in your question...
 
Thanks, I used the wrong terminology because its exactly as you have it with the inheritance...

I ended up figuring it out and getting to work exactly the way I needed it to...

Basically I did this:

Football Namespace
Public Class Form1
Public XCoach as new Generation.Coach

Sub Main()
for i as integer = 0 to 100
XCoach.genCoaches(i, XCoach) '<----Passing the Instance of the Coach Class as a parameter
next i

Generation Namespace
Public Class Coach
Inherits Personnel

Sub New()

End Sub

Public Sub GenCoaches(byval CoachNum as integer, byval XCoach as Coach) '<---Instance of the Coach class gets passed as a parameter

XCoach.FirstName = "blah blah blah" 


Works just as I wanted it to
 
Last edited:

Latest posts

Back
Top