Inheritance

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

    #1

    Inheritance

    Public Class RichBigDaddy
    Public Sub PlayPolo()
    Trace.WriteLine ("RichBigDaddy: :PlayPolo")
    End Sub
    End Class
    Public Class TrustFundSnob
    Inherits RichBigDaddy

    Public Sub PlayPolo()
    Trace.WriteLine ("TrustFundSnob ::PlayPolo")
    End Sub
    End Class========== =============== =============== =========If I want the
    output be :RichBigDaddy:: PlayPoloTrustFu ndSnob::PlayPol oAny sub declaration
    method should be added ? (like shadows, overrides, overloads, etc)I've tried
    to use them all, but the output is only
    :RichBigDaddy:: PlayPoloORTrust FundSnob::PlayP olo


  • Pieter

    #2
    Re: Inheritance

    You want it to print the two lines when calling the PlayPolo of the
    TrustFundSnob?
    Than change it to this:

    Public Class TrustFundSnob
    Inherits RichBigDaddy
    Public Sub PlayPolo()
    MyBase.PlayPolo 4 '-> ADD THIS LINE
    Trace.WriteLine ("TrustFundSnob ::PlayPolo")
    End Sub
    End Class

    I hope this is what you want?


    "Kalim Julia" <kalim.julia@gm ail.com> wrote in message
    news:OhT$cPoFGH A.2704@TK2MSFTN GP15.phx.gbl...[color=blue]
    > Public Class RichBigDaddy
    > Public Sub PlayPolo()
    > Trace.WriteLine ("RichBigDaddy: :PlayPolo")
    > End Sub
    > End Class
    > Public Class TrustFundSnob
    > Inherits RichBigDaddy
    >
    > Public Sub PlayPolo()
    > Trace.WriteLine ("TrustFundSnob ::PlayPolo")
    > End Sub
    > End Class========== =============== =============== =========If I want the
    > output be :RichBigDaddy:: PlayPoloTrustFu ndSnob::PlayPol oAny sub
    > declaration
    > method should be added ? (like shadows, overrides, overloads, etc)I've
    > tried
    > to use them all, but the output is only
    > :RichBigDaddy:: PlayPoloORTrust FundSnob::PlayP olo
    >
    >[/color]


    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Inheritance

      Kalim,

      Is this what you want to do?

      \\\\
      Public Class RichBigDaddy
      Public Overridable Sub PlayPolo()
      Trace.WriteLine ("RichBigDaddy: :PlayPolo")
      End Sub
      End Class
      Public Class TrustFundSnob
      Inherits RichBigDaddy
      Public Overrides Sub PlayPolo()
      MyBase.PlayPolo ()
      Trace.WriteLine ("TrustFundSnob ::PlayPolo")
      End Sub
      End Class
      ///

      I hope this helps,

      Cor


      Comment

      • Kalim Julia

        #4
        Re: Inheritance

        Any other way instead of using MyBase.PlayPolo () ?

        "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
        news:ut9pGNpFGH A.3792@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Kalim,
        >
        > Is this what you want to do?
        >
        > \\\\
        > Public Class RichBigDaddy
        > Public Overridable Sub PlayPolo()
        > Trace.WriteLine ("RichBigDaddy: :PlayPolo")
        > End Sub
        > End Class
        > Public Class TrustFundSnob
        > Inherits RichBigDaddy
        > Public Overrides Sub PlayPolo()
        > MyBase.PlayPolo ()
        > Trace.WriteLine ("TrustFundSnob ::PlayPolo")
        > End Sub
        > End Class
        > ///
        >
        > I hope this helps,
        >
        > Cor
        >
        >[/color]


        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Inheritance

          > Any other way instead of using MyBase.PlayPolo () ?

          Why?


          "Kalim Julia" <kalim.julia@gm ail.com> schreef in bericht
          news:ee2PpfpFGH A.1312@TK2MSFTN GP09.phx.gbl...[color=blue]
          > Any other way instead of using MyBase.PlayPolo () ?
          >
          > "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
          > news:ut9pGNpFGH A.3792@TK2MSFTN GP10.phx.gbl...[color=green]
          >> Kalim,
          >>
          >> Is this what you want to do?
          >>
          >> \\\\
          >> Public Class RichBigDaddy
          >> Public Overridable Sub PlayPolo()
          >> Trace.WriteLine ("RichBigDaddy: :PlayPolo")
          >> End Sub
          >> End Class
          >> Public Class TrustFundSnob
          >> Inherits RichBigDaddy
          >> Public Overrides Sub PlayPolo()
          >> MyBase.PlayPolo ()
          >> Trace.WriteLine ("TrustFundSnob ::PlayPolo")
          >> End Sub
          >> End Class
          >> ///
          >>
          >> I hope this helps,
          >>
          >> Cor
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Kalim Julia

            #6
            Re: Inheritance

            I design this and hoping that my programmers won't do any mistakes like
            forgetting put MyBase.PlayPolo ().
            I just want to reduce the mistakes (something like trigger or store
            procedure in database system).
            Why people made it, because they want to reduce problems.


            "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
            news:%23aOlQjpF GHA.1676@TK2MSF TNGP09.phx.gbl. ..[color=blue][color=green]
            > > Any other way instead of using MyBase.PlayPolo () ?[/color]
            >
            > Why?
            >
            >
            > "Kalim Julia" <kalim.julia@gm ail.com> schreef in bericht
            > news:ee2PpfpFGH A.1312@TK2MSFTN GP09.phx.gbl...[color=green]
            > > Any other way instead of using MyBase.PlayPolo () ?
            > >
            > > "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
            > > news:ut9pGNpFGH A.3792@TK2MSFTN GP10.phx.gbl...[color=darkred]
            > >> Kalim,
            > >>
            > >> Is this what you want to do?
            > >>
            > >> \\\\
            > >> Public Class RichBigDaddy
            > >> Public Overridable Sub PlayPolo()
            > >> Trace.WriteLine ("RichBigDaddy: :PlayPolo")
            > >> End Sub
            > >> End Class
            > >> Public Class TrustFundSnob
            > >> Inherits RichBigDaddy
            > >> Public Overrides Sub PlayPolo()
            > >> MyBase.PlayPolo ()
            > >> Trace.WriteLine ("TrustFundSnob ::PlayPolo")
            > >> End Sub
            > >> End Class
            > >> ///
            > >>
            > >> I hope this helps,
            > >>
            > >> Cor
            > >>
            > >>[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Cor Ligthert [MVP]

              #7
              Re: Inheritance

              As your programmers use that class than that myBase.PlayPolo is in it so
              what is the trouble?

              Cor


              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: Inheritance

                "Kalim Julia" <kalim.julia@gm ail.com> schrieb:[color=blue]
                > Any other way instead of using MyBase.PlayPolo () ?[/color]

                No.

                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://classicvb.org/petition/>

                Comment

                • Armin Zingler

                  #9
                  Re: Inheritance

                  "Kalim Julia" <kalim.julia@gm ail.com> schrieb[color=blue]
                  > I design this and hoping that my programmers won't do any mistakes
                  > like forgetting put MyBase.PlayPolo ().
                  > I just want to reduce the mistakes (something like trigger or store
                  > procedure in database system).
                  > Why people made it, because they want to reduce problems.[/color]


                  In VB 2005, the IDE automatically inserts mybase.proc if you override a
                  procedure.


                  Armin

                  Comment

                  • alantolan@users.com

                    #10
                    Re: Inheritance



                    Sort of....

                    It depends upon how many levels of inheritance you want / will allow.

                    If your developers are just going to inherit from it ONCE and you will
                    ALWAYS want the base functionality to be called then you can try


                    Public Class RichBigDaddy
                    Public Sub PlayPolo()
                    Trace.WriteLine ("RichBigDaddy: :PlayPolo")
                    PlayPoloEx()
                    End Sub
                    Protected Overridable Sub PlayPoloEx()
                    End Sub
                    End Class

                    Public Class TrustFundSnob
                    Inherits RichBigDaddy

                    Protected Overrides Sub PlayPoloEx()
                    Trace.WriteLine ("TrustFundSnob ::PlayPolo")
                    End Sub

                    End Class


                    Your developers implement the nnnEx() version of the function.
                    If you want to enforce implementing it, then make it MustOverrride in
                    the base class, else just leave as is.


                    Dim x as New RichBigDaddy
                    x.PlayPolo()

                    => "RichBigDaddy:: PlayPolo"

                    Dim y as New TrustFundSnob
                    y.PlayPolo()

                    => "RichBigDaddy:: PlayPolo"
                    "TrustFundSnob: :PlayPolo"


                    In more complicated cases - multiple levels of inheritance; want to
                    invoke the method at each level - I would not swear that one could not
                    use reflection to invoke each version but I would REALLY advise against
                    it. The cure would be solution would be worse thant the original
                    problem

                    hth,Alan

                    Comment

                    • Jay B. Harlow [MVP - Outlook]

                      #11
                      Re: Inheritance

                      Alan,
                      Instead of PlayPoloEx, I would consider calling it PlayPoloCore, as using
                      Core is one of the "patterns" that the framework uses. For example
                      Control.Scale calls Control.ScaleCo re to do the "heavy lifting".

                      http://msdn.microsoft.com/library/de...ecoretopic.asp

                      I want to say the above "pattern" is in the "Framework Design Guidelines",
                      however I'm not seeing a specific reference for it in either .NET 1.x or 2.0
                      Design Guidelines...

                      I've also used the convention of calling the overridable method DoPlayPolo &
                      OnPlayPolo...

                      --
                      Hope this helps
                      Jay [MVP - Outlook]
                      ..NET Application Architect, Enthusiast, & Evangelist
                      T.S. Bradley - http://www.tsbradley.net


                      <alantolan@user s.com> wrote in message
                      news:1137020608 .140111.60970@g 44g2000cwa.goog legroups.com...
                      |
                      |
                      | Sort of....
                      |
                      | It depends upon how many levels of inheritance you want / will allow.
                      |
                      | If your developers are just going to inherit from it ONCE and you will
                      | ALWAYS want the base functionality to be called then you can try
                      |
                      |
                      | Public Class RichBigDaddy
                      | Public Sub PlayPolo()
                      | Trace.WriteLine ("RichBigDaddy: :PlayPolo")
                      | PlayPoloEx()
                      | End Sub
                      | Protected Overridable Sub PlayPoloEx()
                      | End Sub
                      | End Class
                      |
                      | Public Class TrustFundSnob
                      | Inherits RichBigDaddy
                      |
                      | Protected Overrides Sub PlayPoloEx()
                      | Trace.WriteLine ("TrustFundSnob ::PlayPolo")
                      | End Sub
                      |
                      | End Class
                      |
                      |
                      | Your developers implement the nnnEx() version of the function.
                      | If you want to enforce implementing it, then make it MustOverrride in
                      | the base class, else just leave as is.
                      |
                      |
                      | Dim x as New RichBigDaddy
                      | x.PlayPolo()
                      |
                      | => "RichBigDaddy:: PlayPolo"
                      |
                      | Dim y as New TrustFundSnob
                      | y.PlayPolo()
                      |
                      | => "RichBigDaddy:: PlayPolo"
                      | "TrustFundSnob: :PlayPolo"
                      |
                      |
                      | In more complicated cases - multiple levels of inheritance; want to
                      | invoke the method at each level - I would not swear that one could not
                      | use reflection to invoke each version but I would REALLY advise against
                      | it. The cure would be solution would be worse thant the original
                      | problem
                      |
                      | hth,Alan
                      |


                      Comment

                      Working...