Inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    #1

    Inheritance

    I am playing with Inheritance and want to make sure I understand it.

    I have the following Classes:
    *************** *************** *************
    Public Class AuthHeader:Inhe rits SoapHeader
    Public AuthHeaderName As String
    Public SessionKey As String = "Default"
    End Class

    Public Class ServiceTicket:I nherits AuthHeader
    Public IsAuthenticated As Boolean
    Public SessionKey As String = "Default from ServiceTicket"
    Public Expiration As DateTime
    End Class

    Public Class TempClass1:Inhe rits ServiceTicket
    Public TomsClass1Name As String
    End Class
    *************** *************** ***********

    I assume that inheritance depends on the order of definition.

    Here SessionKey is being defined in 2 classes. For TempClass1 and
    ServiceTicket, Session would be "Default from ServiceTicket" since it would
    have been defined second. So if I create TempClass1, it would work
    something like, SessionKey would first be "Default" but then ServiceTicket
    would re-define it, since it inherited it (and is higher up the chain) and
    change it to "Default from ServiceTicket".

    In this case, if I had:

    Dim objTempClass1 As new TempClass1
    Dim objServiceTicke t As new ServiceTicket
    Dim objAuthHeader As new AuthHeader

    objTempClass1.S essionKey = "Default from ServiceTicket" '
    Inherited from ServiceKey
    objServiceKey.S essionKey = "Default from ServiceTicket"
    objAuthHeader.S essionKey = "Default"

    But if I took out the Sessionkey from the ServiceKey class that it would be:

    objTempClass1.S essionKey = "Default" ' Inherited from
    AuthHeader
    objServiceKey.S essionKey = "Default" ' Inherited
    from AuthHeader
    objAuthHeader.S essionKey = "Default"

    Also, I originally got this from a sample program that didn't set the
    defaults, but had it defined as:
    *************** *************** *************
    Public Class AuthHeader:Inhe rits SoapHeader
    Public AuthHeaderName As String
    Public SessionKey As String
    End Class

    Public Class ServiceTicket:I nherits AuthHeader
    Public IsAuthenticated As Boolean
    Public SessionKey As String
    Public Expiration As DateTime
    End Class

    Public Class TempClass1:Inhe rits ServiceTicket
    Public TomsClass1Name As String
    End Class
    *************** *************** ***********

    Is there any good reason to defining SessionKey again ServiceTicket?

    I assume since it always would inherit from AuthHeader, it would always get
    SessionKey from the inheritance. If it wanted to set SessionKey in
    ServiceTicket, it could just set it by:

    SessionKey = "Default"

    without needing to redefine it.

    Is this correct?

    Thanks,

    Tom


  • Vijay

    #2
    Re: Inheritance

    yes the reason to override are more applicable to methods, properties yes..
    if you want to additional functionality to than what is available in the
    base class.. I also strongly recommend that any public variables you declare
    and intended to use a property or have thought it must be overridden, given
    them as property definitions its much cleaner that way

    VJ

    "tshad" <tscheiderich@f tsolutions.com> wrote in message
    news:u$wTCq2VGH A.5808@TK2MSFTN GP12.phx.gbl...[color=blue]
    >I am playing with Inheritance and want to make sure I understand it.
    >
    > I have the following Classes:
    > *************** *************** *************
    > Public Class AuthHeader:Inhe rits SoapHeader
    > Public AuthHeaderName As String
    > Public SessionKey As String = "Default"
    > End Class
    >
    > Public Class ServiceTicket:I nherits AuthHeader
    > Public IsAuthenticated As Boolean
    > Public SessionKey As String = "Default from ServiceTicket"
    > Public Expiration As DateTime
    > End Class
    >
    > Public Class TempClass1:Inhe rits ServiceTicket
    > Public TomsClass1Name As String
    > End Class
    > *************** *************** ***********
    >
    > I assume that inheritance depends on the order of definition.
    >
    > Here SessionKey is being defined in 2 classes. For TempClass1 and
    > ServiceTicket, Session would be "Default from ServiceTicket" since it
    > would have been defined second. So if I create TempClass1, it would work
    > something like, SessionKey would first be "Default" but then ServiceTicket
    > would re-define it, since it inherited it (and is higher up the chain) and
    > change it to "Default from ServiceTicket".
    >
    > In this case, if I had:
    >
    > Dim objTempClass1 As new TempClass1
    > Dim objServiceTicke t As new ServiceTicket
    > Dim objAuthHeader As new AuthHeader
    >
    > objTempClass1.S essionKey = "Default from ServiceTicket" '
    > Inherited from ServiceKey
    > objServiceKey.S essionKey = "Default from ServiceTicket"
    > objAuthHeader.S essionKey = "Default"
    >
    > But if I took out the Sessionkey from the ServiceKey class that it would
    > be:
    >
    > objTempClass1.S essionKey = "Default" ' Inherited
    > from AuthHeader
    > objServiceKey.S essionKey = "Default" ' Inherited
    > from AuthHeader
    > objAuthHeader.S essionKey = "Default"
    >
    > Also, I originally got this from a sample program that didn't set the
    > defaults, but had it defined as:
    > *************** *************** *************
    > Public Class AuthHeader:Inhe rits SoapHeader
    > Public AuthHeaderName As String
    > Public SessionKey As String
    > End Class
    >
    > Public Class ServiceTicket:I nherits AuthHeader
    > Public IsAuthenticated As Boolean
    > Public SessionKey As String
    > Public Expiration As DateTime
    > End Class
    >
    > Public Class TempClass1:Inhe rits ServiceTicket
    > Public TomsClass1Name As String
    > End Class
    > *************** *************** ***********
    >
    > Is there any good reason to defining SessionKey again ServiceTicket?
    >
    > I assume since it always would inherit from AuthHeader, it would always
    > get SessionKey from the inheritance. If it wanted to set SessionKey in
    > ServiceTicket, it could just set it by:
    >
    > SessionKey = "Default"
    >
    > without needing to redefine it.
    >
    > Is this correct?
    >
    > Thanks,
    >
    > Tom
    >
    >[/color]


    Comment

    • tshad

      #3
      Re: Inheritance

      "Vijay" <vijay@msdiscus sions.com> wrote in message
      news:e4p7432VGH A.4416@TK2MSFTN GP15.phx.gbl...[color=blue]
      > yes the reason to override are more applicable to methods, properties
      > yes.. if you want to additional functionality to than what is available in
      > the base class.. I also strongly recommend that any public variables you
      > declare and intended to use a property or have thought it must be
      > overridden, given them as property definitions its much cleaner that way[/color]

      I agree.

      This was just a quick example of the what I was trying to play with. I just
      wanted to make sure I was understanding what was happening correctly.

      I wasn't sure if there was 1 variable or 2. I assume it was 1 and the last
      defined one was the one I would see.

      I heard from someone else that if I wanted 2 variables I would define it as
      shadows (override being the default). I would still get the last defined
      one, but I could also get the one in the base class by using the base class
      name with the variable. Not sure why I would need that, but I am sure there
      are good reasons for it. Right now I am just trying to get the basics of
      inheritance down. I understand it, I just haven't build any objects that
      were inherited by another object (other than the normal system ones).

      Thanks,

      Tom[color=blue]
      >
      > VJ
      >
      > "tshad" <tscheiderich@f tsolutions.com> wrote in message
      > news:u$wTCq2VGH A.5808@TK2MSFTN GP12.phx.gbl...[color=green]
      >>I am playing with Inheritance and want to make sure I understand it.
      >>
      >> I have the following Classes:
      >> *************** *************** *************
      >> Public Class AuthHeader:Inhe rits SoapHeader
      >> Public AuthHeaderName As String
      >> Public SessionKey As String = "Default"
      >> End Class
      >>
      >> Public Class ServiceTicket:I nherits AuthHeader
      >> Public IsAuthenticated As Boolean
      >> Public SessionKey As String = "Default from ServiceTicket"
      >> Public Expiration As DateTime
      >> End Class
      >>
      >> Public Class TempClass1:Inhe rits ServiceTicket
      >> Public TomsClass1Name As String
      >> End Class
      >> *************** *************** ***********
      >>
      >> I assume that inheritance depends on the order of definition.
      >>
      >> Here SessionKey is being defined in 2 classes. For TempClass1 and
      >> ServiceTicket, Session would be "Default from ServiceTicket" since it
      >> would have been defined second. So if I create TempClass1, it would work
      >> something like, SessionKey would first be "Default" but then
      >> ServiceTicket would re-define it, since it inherited it (and is higher up
      >> the chain) and change it to "Default from ServiceTicket".
      >>
      >> In this case, if I had:
      >>
      >> Dim objTempClass1 As new TempClass1
      >> Dim objServiceTicke t As new ServiceTicket
      >> Dim objAuthHeader As new AuthHeader
      >>
      >> objTempClass1.S essionKey = "Default from ServiceTicket" '
      >> Inherited from ServiceKey
      >> objServiceKey.S essionKey = "Default from ServiceTicket"
      >> objAuthHeader.S essionKey = "Default"
      >>
      >> But if I took out the Sessionkey from the ServiceKey class that it would
      >> be:
      >>
      >> objTempClass1.S essionKey = "Default" ' Inherited
      >> from AuthHeader
      >> objServiceKey.S essionKey = "Default" ' Inherited
      >> from AuthHeader
      >> objAuthHeader.S essionKey = "Default"
      >>
      >> Also, I originally got this from a sample program that didn't set the
      >> defaults, but had it defined as:
      >> *************** *************** *************
      >> Public Class AuthHeader:Inhe rits SoapHeader
      >> Public AuthHeaderName As String
      >> Public SessionKey As String
      >> End Class
      >>
      >> Public Class ServiceTicket:I nherits AuthHeader
      >> Public IsAuthenticated As Boolean
      >> Public SessionKey As String
      >> Public Expiration As DateTime
      >> End Class
      >>
      >> Public Class TempClass1:Inhe rits ServiceTicket
      >> Public TomsClass1Name As String
      >> End Class
      >> *************** *************** ***********
      >>
      >> Is there any good reason to defining SessionKey again ServiceTicket?
      >>
      >> I assume since it always would inherit from AuthHeader, it would always
      >> get SessionKey from the inheritance. If it wanted to set SessionKey in
      >> ServiceTicket, it could just set it by:
      >>
      >> SessionKey = "Default"
      >>
      >> without needing to redefine it.
      >>
      >> Is this correct?
      >>
      >> Thanks,
      >>
      >> Tom
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • Vijay

        #4
        Re: Inheritance

        Personally I will try to avoid shadows.. as much as I can.. it just causes
        confusion in readability. That is what I have seen in huge projects..

        Vijay

        "tshad" <tscheiderich@f tsolutions.com> wrote in message
        news:eProSo3VGH A.4724@TK2MSFTN GP09.phx.gbl...[color=blue]
        > "Vijay" <vijay@msdiscus sions.com> wrote in message
        > news:e4p7432VGH A.4416@TK2MSFTN GP15.phx.gbl...[color=green]
        >> yes the reason to override are more applicable to methods, properties
        >> yes.. if you want to additional functionality to than what is available
        >> in the base class.. I also strongly recommend that any public variables
        >> you declare and intended to use a property or have thought it must be
        >> overridden, given them as property definitions its much cleaner that way[/color]
        >
        > I agree.
        >
        > This was just a quick example of the what I was trying to play with. I
        > just wanted to make sure I was understanding what was happening correctly.
        >
        > I wasn't sure if there was 1 variable or 2. I assume it was 1 and the
        > last defined one was the one I would see.
        >
        > I heard from someone else that if I wanted 2 variables I would define it
        > as shadows (override being the default). I would still get the last
        > defined one, but I could also get the one in the base class by using the
        > base class name with the variable. Not sure why I would need that, but I
        > am sure there are good reasons for it. Right now I am just trying to get
        > the basics of inheritance down. I understand it, I just haven't build any
        > objects that were inherited by another object (other than the normal
        > system ones).
        >
        > Thanks,
        >
        > Tom[color=green]
        >>
        >> VJ
        >>
        >> "tshad" <tscheiderich@f tsolutions.com> wrote in message
        >> news:u$wTCq2VGH A.5808@TK2MSFTN GP12.phx.gbl...[color=darkred]
        >>>I am playing with Inheritance and want to make sure I understand it.
        >>>
        >>> I have the following Classes:
        >>> *************** *************** *************
        >>> Public Class AuthHeader:Inhe rits SoapHeader
        >>> Public AuthHeaderName As String
        >>> Public SessionKey As String = "Default"
        >>> End Class
        >>>
        >>> Public Class ServiceTicket:I nherits AuthHeader
        >>> Public IsAuthenticated As Boolean
        >>> Public SessionKey As String = "Default from ServiceTicket"
        >>> Public Expiration As DateTime
        >>> End Class
        >>>
        >>> Public Class TempClass1:Inhe rits ServiceTicket
        >>> Public TomsClass1Name As String
        >>> End Class
        >>> *************** *************** ***********
        >>>
        >>> I assume that inheritance depends on the order of definition.
        >>>
        >>> Here SessionKey is being defined in 2 classes. For TempClass1 and
        >>> ServiceTicket, Session would be "Default from ServiceTicket" since it
        >>> would have been defined second. So if I create TempClass1, it would
        >>> work something like, SessionKey would first be "Default" but then
        >>> ServiceTicket would re-define it, since it inherited it (and is higher
        >>> up the chain) and change it to "Default from ServiceTicket".
        >>>
        >>> In this case, if I had:
        >>>
        >>> Dim objTempClass1 As new TempClass1
        >>> Dim objServiceTicke t As new ServiceTicket
        >>> Dim objAuthHeader As new AuthHeader
        >>>
        >>> objTempClass1.S essionKey = "Default from ServiceTicket" '
        >>> Inherited from ServiceKey
        >>> objServiceKey.S essionKey = "Default from ServiceTicket"
        >>> objAuthHeader.S essionKey = "Default"
        >>>
        >>> But if I took out the Sessionkey from the ServiceKey class that it would
        >>> be:
        >>>
        >>> objTempClass1.S essionKey = "Default" ' Inherited
        >>> from AuthHeader
        >>> objServiceKey.S essionKey = "Default" ' Inherited
        >>> from AuthHeader
        >>> objAuthHeader.S essionKey = "Default"
        >>>
        >>> Also, I originally got this from a sample program that didn't set the
        >>> defaults, but had it defined as:
        >>> *************** *************** *************
        >>> Public Class AuthHeader:Inhe rits SoapHeader
        >>> Public AuthHeaderName As String
        >>> Public SessionKey As String
        >>> End Class
        >>>
        >>> Public Class ServiceTicket:I nherits AuthHeader
        >>> Public IsAuthenticated As Boolean
        >>> Public SessionKey As String
        >>> Public Expiration As DateTime
        >>> End Class
        >>>
        >>> Public Class TempClass1:Inhe rits ServiceTicket
        >>> Public TomsClass1Name As String
        >>> End Class
        >>> *************** *************** ***********
        >>>
        >>> Is there any good reason to defining SessionKey again ServiceTicket?
        >>>
        >>> I assume since it always would inherit from AuthHeader, it would always
        >>> get SessionKey from the inheritance. If it wanted to set SessionKey in
        >>> ServiceTicket, it could just set it by:
        >>>
        >>> SessionKey = "Default"
        >>>
        >>> without needing to redefine it.
        >>>
        >>> Is this correct?
        >>>
        >>> Thanks,
        >>>
        >>> Tom
        >>>
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        Working...