P
Peter Hamilton
I am trying to implement inheritance but I am having a difficult time with some concepts.
What I am trying to do is have a Child object inherit from the Parent, and when you set a property value at the Parent level, I want all of the children to see this change. Likewise, when I set a Parent's property value in the child object, both the parent and all of the children see the change.
Maybe what I am trying to do is not "inheritance" after all. But, if anyone can point me in the right direction it would be appreciated.
Sample simple VB code is below (I have omitted the #Region " Windows Form Designer generated code " stuff)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oParent As New Parent() '//Parent Object
Dim oChild As New Child() '//Child inherits from Parent
oParent.ParentName = "I set this for the parent!" '//Set the parent's value
MessageBox.Show("oParent.ParentName = '" & oParent.ParentName & "'" & vbCrLf & vbCrLf & "oChild.ParentName = '" & oChild.ParentName & "'") '//This returns an empty string!! (I want the child to know about its parent's value!!!)
End Sub
End Class
Public Class Parent
Private m_ParentName As String
Public Property ParentName()
Get
Return m_ParentName
End Get
Set(ByVal Value)
m_ParentName = Value
End Set
End Property
End Class
'//No methods, I just want to see if we can see the parent's name...
Public Class Child
Inherits Parent
End Class
What I am trying to do is have a Child object inherit from the Parent, and when you set a property value at the Parent level, I want all of the children to see this change. Likewise, when I set a Parent's property value in the child object, both the parent and all of the children see the change.
Maybe what I am trying to do is not "inheritance" after all. But, if anyone can point me in the right direction it would be appreciated.
Sample simple VB code is below (I have omitted the #Region " Windows Form Designer generated code " stuff)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oParent As New Parent() '//Parent Object
Dim oChild As New Child() '//Child inherits from Parent
oParent.ParentName = "I set this for the parent!" '//Set the parent's value
MessageBox.Show("oParent.ParentName = '" & oParent.ParentName & "'" & vbCrLf & vbCrLf & "oChild.ParentName = '" & oChild.ParentName & "'") '//This returns an empty string!! (I want the child to know about its parent's value!!!)
End Sub
End Class
Public Class Parent
Private m_ParentName As String
Public Property ParentName()
Get
Return m_ParentName
End Get
Set(ByVal Value)
m_ParentName = Value
End Set
End Property
End Class
'//No methods, I just want to see if we can see the parent's name...
Public Class Child
Inherits Parent
End Class