URGENT! - Using Shawdow variables in VB.NET Classes

I created a class that wraps an XML node.  The class is named Human because it is used to wrap many different person nodes in my XML document.  Example:

<Approver Name="Bob" ActionDate="2003/12/03" SomethingElse="Blah Blah"/>
<Performer Name="sam" ActionDate="2003/11/03" SomethingElse="Blah Blah"/>
<Creator Name="ralph" ActionDate="2003/1/03" SomethingElse="Blah Blah"/>

I want to use the Human class but I need to change it's name.  I tried the Shadow keyword in both the Human class and the higher classes, but that doesn't work, I can't set the name in the higher class without explicitly setting the name a run-time (which is sloppy).

In my project, each class is constructed such:
Class clsApprover
  inherits Human
  Shadows HumanName as String = "Approver"
End Class

Class Human
  Shadows HumanName as String
 
'Check for parent node and thisNode, create if necessary
   Private Function HasNode() As Boolean
      If IsNothing(pNode.GetElementsByTagName(HumanName).Item(0)) Then
        thisNode = xmlALN.CreateElement(HumanName)
        pNode.AppendChild(thisNode)
        Return True
      Else
        thisNode = pNode.GetElementsByTagName(HumanName).Item(0)
      End If
    End Function


Any idea how I can do this efficiently?

Thanks,
Jeffrey
OgilbeeJAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OgilbeeJAuthor Commented:
I discovered a way to do what I'm looking for but it's sloppy and I just know there's a better way.

  Public Class clsCreator
    Inherits clsHuman
    Friend Overrides Property HumanName() As String
      Get
        Return MyBase.HumanName
      End Get
      Set(ByVal Value As String)
        MyBase.HumanName = Value
      End Set
    End Property
    Public Sub New()
      HumanName = "Creator"
    End Sub
  End Class

  Public Class clsHuman
    'parent node is the node that will be checked for the child
    Public pNode As System.Xml.XmlElement
    Private thisNode As System.Xml.XmlElement
    Private hName As String = ""
    Friend Overridable Property HumanName() As String
      Get
        Return hName
      End Get
      Set(ByVal Value As String)
        hName = Value
      End Set
    End Property
    Private Function HasNode() As Boolean
      If pNode Is Nothing Then Return False
      If IsNothing(pNode.GetElementsByTagName(hName).Item(0)) Then
        thisNode = xmlALN.CreateElement(hName)
        pNode.AppendChild(thisNode)
        Return True
      Else
        thisNode = pNode.GetElementsByTagName(hName).Item(0)
        Return True
      End If
    End Function
...
End Class

Is there a better way?  

Also, is there any way to use XPath with a SmartDevice project in VB.NET?  I am really comfortable with the MSXML2 SelectSingleNode(xPath) and SelectNodes(xPath) functions, but System.XML doesn't seem to support that methodology.  Should this be a seperate post or can someone give me a quick example?


0
malharoneCommented:
no .. your class definition seem alright ... and yes you're right .. you "inherit" the class ... not "shadow" it.
0
OgilbeeJAuthor Commented:
Thanks malharone, but I just want to believe there is a way to inherit a class and set default properties without overriding.  

Why doesn't the following code work?
 Public Class clsCreator
    Inherits clsHuman
    MyBase.HumanName = "Creator"
  End Class
0
malharoneCommented:
okay ... sorry ...
from your post:
 Public Class clsCreator
    Inherits clsHuman
    MyBase.HumanName = "Creator"     '<-- if you're doing this w/o instantiating parent object , then you're in trouble
  End Class





'**************************************************************
'i'm using MustInherit if you want this class not to
'be directly instantiated, but only indirectly through a
'derived class .. but depending upon your application, you may
'wish to remove it
'**************************************************************
Public MustInherit Class clsHuman
    Public pNode As System.Xml.XmlElement
    Private thisNode As System.Xml.XmlElement
    Private hName As String = ""

    '**************************************************************
    'protected means all inherited classes have access to this
    'If you change 'protected' to 'public' not only will the derived classes
    '   have access to it, but also all other classes that have the objects
    '   of type clsHuman or any other class deriving clsHuman
    'check out http://visualbasic.about.com/library/blinheritancea.htm 
    ' for further clarification
    '**************************************************************
    Protected Property HumanName() As String
        Get
            Return hName
        End Get
        Set(ByVal Value As String)
            hName = Value
        End Set
    End Property
    Private Function HasNode() As Boolean
        'your code
    End Function
    Public Sub New()
        'your initialization code
    End Sub
End Class
Public Class clsCreator
    Inherits clsHuman

    Public Sub New()
        MyBase.New()
        '**************************************************************
        ' you should always call MyBase.New for inheriting classes
        '**************************************************************

        '**************************************************************
        'it's also a good practice to be as explicit as possible
        'e.g. using MyBase.HumanName instead of HumanName
        '**************************************************************
        MyBase.HumanName = "Creator"
    End Sub
End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OgilbeeJAuthor Commented:
DanRollins --> Yes, mahoarones answer was very helpful.  I appologize for not responding sooner, I got pulled on to another project and forgot to check back here.  
malharone --> Thanks for the snipit, your help is appreciated.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.