I'm not sure really what to do here- use a list or create 2 separate classes to accomplish this:
I want to create 2 classes in my project- one called Person which defines the Person class and another called People which defines a class containing many People - maybe up to 100 or so. I have tried a few things but run into a problem as I will explain in the code fragment below:
class module 1(person.bas):
AI would like to leave the fields in the Person Class Private because I might want to deal with this class individually outside of the Persons Class. If I use get...set methods in the Person Class how can I put them to use with the People Class?
I'm confused, What should I do? All of the examples of class definitions here have the individual elements in a class declared as private not public as I have done in order to get this to work.
Is this called subclassing? Not really sure because just learning OOP here.
Regards,
Ray
I want to create 2 classes in my project- one called Person which defines the Person class and another called People which defines a class containing many People - maybe up to 100 or so. I have tried a few things but run into a problem as I will explain in the code fragment below:
class module 1(person.bas):
B4X:
'Class module
Sub Class_Globals
Private FirstName, LastName As String
Private Age As int
End Sub
Public Sub Initialize ...
End Sub
------
class module 2 (people.bas):
'Class module
Sub Class_Globals
Private MAXPEOPLE As Int: MAXPEOPLE = 100
Private People(MAXPEOPLE) As Person ' array of person classes
End Sub
Public Sub Initialize (...)
End Sub
'In module 2 I cannot reference individual fields of the Person class from the 'array because they are defined as "private".
'if I try to reference the 'name field from the first entry in the array as follows it cannot be accessed:
Public Sub GetFirstName (idx AS Int) As String
return People(idx).FirstName
EndSub
'however,
'if I declare the Person Class in the following manner all works fine:
class module 1(person.bas):
'Class module
Sub Class_Globals
Dim FirstName, LastName As String
Dim Age As int
End Sub
Public Sub Initialize ...
End Sub
AI would like to leave the fields in the Person Class Private because I might want to deal with this class individually outside of the Persons Class. If I use get...set methods in the Person Class how can I put them to use with the People Class?
I'm confused, What should I do? All of the examples of class definitions here have the individual elements in a class declared as private not public as I have done in order to get this to work.
Is this called subclassing? Not really sure because just learning OOP here.
Regards,
Ray