I have a Class FileDoc
Public Class FileDoc
Inherits BaseClass
Public Sub DeleteDoc()
dim catId as integer = Cat_ID
End Sub
a bunch of properties...
End Class
And I have another Class…
Public Class BaseClass
Private _Cat_ID As Integer
Public Property Cat_ID() As Integer
Get
Return _Cat_ID
End Get
Set(ByVal value As Integer)
_Cat_ID = value
AssignAllInfo()
End Set
End Property
Private _Docs As List(Of FileDoc)
Public Property Docs() As List(Of FileDoc)
Get
Return _Docs
End Get
Set(ByVal value As List(Of FileDoc))
_Docs = value
End Set
End Property
My question is, since FileDoc comes from the BaseClass, how can I access values from the BaseClass when I’m coding in the FileDoc Class. Like my example in sub DeleteDoc(), I’m trying to access the Cat_ID of the Base Class which this FileDoc belongs to.
Adding an inheritance doesn’t transfer the values to the class, only the properties.
Thx in advance
Inheritance doesn’t do that. Keep in mind that you are working with Classes which is a kind of template for your object. You’re mixing that up with instances which is an instantiated version of your class that contains data.
For example, when you create an instance of
FileDoc, you are getting a blank object that contains fields from bothBaseClassandFileDoc.FileDochas no idea if there are other instances ofBaseClassthat contain data (nor should it). Think about it this way – if you had multipleBaseClassinstances and then you instantiated aFileDocclass, whichBaseClassinstance should it use to populate data?There are two ways to go about what you want to do. First, you can imagine your
BaseClassto be abstract (not sure how to do this in VB). So you will not instantiate any instances ofBaseClass.BaseClasssolely exists to provide a base from which other classes can inherit. So, what you will do is instantiateFileDocand then populate it with the data you need.Your other option is have a
BaseClass, but not inherit from it. Instead you can think ofFileDocas a wrapper that acceptsBaseClassas a parameter. So this means thatFileDochas a private member that is of typeBaseClass. This way you don’t need to inherit, but you have access to data fromBaseClass.Choose the method that is appropriate for your situation.