How do I do MyBase.MyBase?

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

    How do I do MyBase.MyBase?

    I realize that MyBase.MyBase is illegal, so how DO I get to the Parent of
    MyBase?

    In Short what is the VB equivalent of "::"?

    Example:

    Class Component
    Inherits Hashtable

    Public Shadows Sub Add()
    'Extra Add stuf for this component
    End Sub
    End Class

    ~~~~~~~~~~~~~~~
    Class BetterComponent
    Inherits Component

    Public Shadows Sub Add()
    'How do I get to the Hashtable.Add and skip the "Extra Component" stuff??
    End Sub
    End Class


  • steve

    #2
    Re: How do I do MyBase.MyBase?

    haven't thought of that...have you tried:

    if not typeof mybase is [type of object you want to deal with] then return
    dim whatever as [type of object you want to deal with] = mybase
    'do whatever you want to do from here

    btw, the base of a base is not a "parent".

    hth,

    steve


    "Henry Padilla" <padillah@hotma il.com> wrote in message
    news:_Dtgd.2463 6$Qv5.7423@news svr33.news.prod igy.com...
    |I realize that MyBase.MyBase is illegal, so how DO I get to the Parent of
    | MyBase?
    |
    | In Short what is the VB equivalent of "::"?
    |
    | Example:
    |
    | Class Component
    | Inherits Hashtable
    |
    | Public Shadows Sub Add()
    | 'Extra Add stuf for this component
    | End Sub
    | End Class
    |
    | ~~~~~~~~~~~~~~~
    | Class BetterComponent
    | Inherits Component
    |
    | Public Shadows Sub Add()
    | 'How do I get to the Hashtable.Add and skip the "Extra Component"
    stuff??
    | End Sub
    | End Class
    |
    |


    Comment

    • Henry Padilla

      #3
      Re: How do I do MyBase.MyBase?

      Yes, but I don't want to simply return I want to go up the inheritance tree
      to the parent class (in code it's not necessarily a parent, in class
      hierarchy it is).

      Henry Padilla


      "steve" <a@b.com> wrote in message
      news:10o4s44q8l vmg47@corp.supe rnews.com...[color=blue]
      > haven't thought of that...have you tried:
      >
      > if not typeof mybase is [type of object you want to deal with] then return
      > dim whatever as [type of object you want to deal with] = mybase
      > 'do whatever you want to do from here
      >
      > btw, the base of a base is not a "parent".
      >
      > hth,
      >
      > steve
      >
      >
      > "Henry Padilla" <padillah@hotma il.com> wrote in message
      > news:_Dtgd.2463 6$Qv5.7423@news svr33.news.prod igy.com...
      > |I realize that MyBase.MyBase is illegal, so how DO I get to the Parent of
      > | MyBase?
      > |
      > | In Short what is the VB equivalent of "::"?
      > |
      > | Example:
      > |
      > | Class Component
      > | Inherits Hashtable
      > |
      > | Public Shadows Sub Add()
      > | 'Extra Add stuf for this component
      > | End Sub
      > | End Class
      > |
      > | ~~~~~~~~~~~~~~~
      > | Class BetterComponent
      > | Inherits Component
      > |
      > | Public Shadows Sub Add()
      > | 'How do I get to the Hashtable.Add and skip the "Extra Component"
      > stuff??
      > | End Sub
      > | End Class
      > |
      > |
      >
      >[/color]


      Comment

      • Marina

        #4
        Re: How do I do MyBase.MyBase?

        I don't think this is possible, though I could be wrong.

        Besides, how would this work if your class inherited from object and didn't
        have a 'grandparent'?

        "Henry Padilla" <padillah@hotma il.com> wrote in message
        news:vyugd.1779 0$5b1.8297@news svr17.news.prod igy.com...[color=blue]
        > Yes, but I don't want to simply return I want to go up the inheritance[/color]
        tree[color=blue]
        > to the parent class (in code it's not necessarily a parent, in class
        > hierarchy it is).
        >
        > Henry Padilla
        >
        >
        > "steve" <a@b.com> wrote in message
        > news:10o4s44q8l vmg47@corp.supe rnews.com...[color=green]
        > > haven't thought of that...have you tried:
        > >
        > > if not typeof mybase is [type of object you want to deal with] then[/color][/color]
        return[color=blue][color=green]
        > > dim whatever as [type of object you want to deal with] = mybase
        > > 'do whatever you want to do from here
        > >
        > > btw, the base of a base is not a "parent".
        > >
        > > hth,
        > >
        > > steve
        > >
        > >
        > > "Henry Padilla" <padillah@hotma il.com> wrote in message
        > > news:_Dtgd.2463 6$Qv5.7423@news svr33.news.prod igy.com...
        > > |I realize that MyBase.MyBase is illegal, so how DO I get to the Parent[/color][/color]
        of[color=blue][color=green]
        > > | MyBase?
        > > |
        > > | In Short what is the VB equivalent of "::"?
        > > |
        > > | Example:
        > > |
        > > | Class Component
        > > | Inherits Hashtable
        > > |
        > > | Public Shadows Sub Add()
        > > | 'Extra Add stuf for this component
        > > | End Sub
        > > | End Class
        > > |
        > > | ~~~~~~~~~~~~~~~
        > > | Class BetterComponent
        > > | Inherits Component
        > > |
        > > | Public Shadows Sub Add()
        > > | 'How do I get to the Hashtable.Add and skip the "Extra Component"
        > > stuff??
        > > | End Sub
        > > | End Class
        > > |
        > > |
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Ken Dopierala Jr.

          #5
          Re: How do I do MyBase.MyBase?

          ALL YOUR BASE ARE BELONG TO US!

          Sorry...had to say it.

          Anyway, since it looks like you are trying to do this for components you are
          writing, why not just add a property to the Component class you wrote that
          returns what you are looking for. If this property doesn't exist then
          you'll know that you've gone as far back as you can go. Good luck! Ken.

          --
          Ken Dopierala Jr.
          For great ASP.Net web hosting try:

          If you sign up under me and need help, email me.

          "Henry Padilla" <padillah@hotma il.com> wrote in message
          news:_Dtgd.2463 6$Qv5.7423@news svr33.news.prod igy.com...[color=blue]
          > I realize that MyBase.MyBase is illegal, so how DO I get to the Parent of
          > MyBase?
          >
          > In Short what is the VB equivalent of "::"?
          >
          > Example:
          >
          > Class Component
          > Inherits Hashtable
          >
          > Public Shadows Sub Add()
          > 'Extra Add stuf for this component
          > End Sub
          > End Class
          >
          > ~~~~~~~~~~~~~~~
          > Class BetterComponent
          > Inherits Component
          >
          > Public Shadows Sub Add()
          > 'How do I get to the Hashtable.Add and skip the "Extra Component"[/color]
          stuff??[color=blue]
          > End Sub
          > End Class
          >
          >[/color]


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: How do I do MyBase.MyBase?

            "Henry Padilla" <padillah@hotma il.com> schrieb:[color=blue]
            >I realize that MyBase.MyBase is illegal, so how DO I get to
            > the Parent of MyBase?[/color]

            You cannot. This could lead to unintended use of a class.

            --
            Herfried K. Wagner [MVP]
            <URL:http://dotnet.mvps.org/>

            Comment

            • steve

              #7
              Re: How do I do MyBase.MyBase?

              so what you're saying herf, is that vb doesn't define scope and interface
              access correctly...sin ce most other oop languages do give access to
              traversing underlying classes...i.e. "::" ?


              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
              news:upIatxzvEH A.1300@TK2MSFTN GP14.phx.gbl...
              | "Henry Padilla" <padillah@hotma il.com> schrieb:
              | >I realize that MyBase.MyBase is illegal, so how DO I get to
              | > the Parent of MyBase?
              |
              | You cannot. This could lead to unintended use of a class.
              |
              | --
              | Herfried K. Wagner [MVP]
              | <URL:http://dotnet.mvps.org/>


              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: How do I do MyBase.MyBase?

                Hi ste,

                "steve" <a@b.com> schrieb:[color=blue]
                > so what you're saying herf, is that vb doesn't define scope and interface
                > access correctly...sin ce most other oop languages do give access to
                > traversing underlying classes...i.e. "::" ?[/color]

                In VB.NET, C#, and Java access is resticted to the direct base class to
                prevent inconsistencies in an object's state. Consider this sample:

                \\\
                Public Class A
                Private m_Sum As Integer

                Public Overridable Sub Add(ByVal Number As Integer)
                m_Sum += Number
                End Sub
                End Class

                Public Class B
                Inherits A

                Private m_Checksum As Integer

                Public Overrides Sub Add(ByVal Number As Integer)
                MyBase.Add(Numb er)
                m_Checksum = ...
                End Sub
                End Class

                Public Class C
                Inherits B

                ' Objects of type 'C' are objects of type 'B' too. 'B' guarantees
                ' that the checksum will be set properly. If there was a way to
                ' call 'A''s 'Add' method directly, the checksum set in 'B' would
                ' not be updated and thus the class' state would be inconsistent.
                End Class
                ///

                --
                Herfried K. Wagner [MVP]
                <URL:http://dotnet.mvps.org/>

                Comment

                • Jay B. Harlow [MVP - Outlook]

                  #9
                  Re: How do I do MyBase.MyBase?

                  Steve,[color=blue]
                  > so what you're saying herf, is that vb doesn't define scope and interface
                  > access correctly...sin ce most other oop languages do give access to
                  > traversing underlying classes...i.e. "::" ?[/color]
                  Most?

                  C# has the same safety net, I believe Managed C++ does also. Java does, I
                  don't know Smalltalk or Eiffel well enough to say, I would not be surprised
                  if they had the same safety net also.

                  Only language that I remember that allows this is C++, even there I remember
                  it was discouraged. I want to say one of Scott Meyers "Effective C++" books
                  touched on it, however I am not seeing the reference right now.


                  My understanding is it is enforced by the CLR itself, as knowing who your
                  grand base class is not really needed in OOP. You shouldn't really care or
                  know who your grand base class is, as your class lineage can change, both
                  who your inherit from & what they implement, which is why I understand
                  referring to specific base classes, other then your immediate parent, in C++
                  is frowned upon also.

                  My biggest concern is you might bypass code that is "Required" by the class
                  hierarchy, for example, if Derived class calls a GrandBase function
                  directly, by-passing a Base function, where the Base function is needed for
                  the entire hierarchy to function correctly...

                  IMHO: I actually see the restriction as fixing a scope & interface access
                  problem that older OOP languages exhibit.

                  Just a thought
                  Jay




                  "steve" <a@b.com> wrote in message
                  news:10o9tmug9c cb4fb@corp.supe rnews.com...[color=blue]
                  > so what you're saying herf, is that vb doesn't define scope and interface
                  > access correctly...sin ce most other oop languages do give access to
                  > traversing underlying classes...i.e. "::" ?
                  >
                  >
                  > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                  > news:upIatxzvEH A.1300@TK2MSFTN GP14.phx.gbl...
                  > | "Henry Padilla" <padillah@hotma il.com> schrieb:
                  > | >I realize that MyBase.MyBase is illegal, so how DO I get to
                  > | > the Parent of MyBase?
                  > |
                  > | You cannot. This could lead to unintended use of a class.
                  > |
                  > | --
                  > | Herfried K. Wagner [MVP]
                  > | <URL:http://dotnet.mvps.org/>
                  >
                  >[/color]


                  Comment

                  • Henry Padilla

                    #10
                    Re: How do I do MyBase.MyBase?

                    Thanks! This is exactly what I needed, and why.

                    Tons of help.

                    I am going to have to take the time and implement my base class correctly to
                    begin with.

                    Henry Padilla



                    "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                    news:u5PyNk1vEH A.1452@TK2MSFTN GP11.phx.gbl...[color=blue]
                    > Hi ste,
                    >
                    > "steve" <a@b.com> schrieb:[color=green]
                    > > so what you're saying herf, is that vb doesn't define scope and[/color][/color]
                    interface[color=blue][color=green]
                    > > access correctly...sin ce most other oop languages do give access to
                    > > traversing underlying classes...i.e. "::" ?[/color]
                    >
                    > In VB.NET, C#, and Java access is resticted to the direct base class to
                    > prevent inconsistencies in an object's state. Consider this sample:
                    >
                    > \\\
                    > Public Class A
                    > Private m_Sum As Integer
                    >
                    > Public Overridable Sub Add(ByVal Number As Integer)
                    > m_Sum += Number
                    > End Sub
                    > End Class
                    >
                    > Public Class B
                    > Inherits A
                    >
                    > Private m_Checksum As Integer
                    >
                    > Public Overrides Sub Add(ByVal Number As Integer)
                    > MyBase.Add(Numb er)
                    > m_Checksum = ...
                    > End Sub
                    > End Class
                    >
                    > Public Class C
                    > Inherits B
                    >
                    > ' Objects of type 'C' are objects of type 'B' too. 'B' guarantees
                    > ' that the checksum will be set properly. If there was a way to
                    > ' call 'A''s 'Add' method directly, the checksum set in 'B' would
                    > ' not be updated and thus the class' state would be inconsistent.
                    > End Class
                    > ///
                    >
                    > --
                    > Herfried K. Wagner [MVP]
                    > <URL:http://dotnet.mvps.org/>
                    >[/color]


                    Comment

                    Working...