Hiding inherited members

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

    Hiding inherited members

    I've created a class derived from NativeWindow. The public methods are
    visible to consumers of my class and I don't wish them to be. How does one
    hide those members?

    Best



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003


  • Mike M

    #2
    Hiding inherited members

    I was actually going to ask the same question. I'll give
    you an example though.

    If you look at the TrackBar control, there is no Text
    property because there is no text rendered on the
    control. The TrackBar inherits from the Control class,
    which does have a Text property.

    From what I understand, using the keyword new is supposed
    to allow you to replace an inherited function with your
    own. This doesn't work if you change the scope.

    If I remember correctly, changing the scope does work in
    VB with the Shadows keyword. I would assume that C#
    would have some way to do it.
    [color=blue]
    >-----Original Message-----
    >I've created a class derived from NativeWindow. The[/color]
    public methods are[color=blue]
    >visible to consumers of my class and I don't wish them[/color]
    to be. How does one[color=blue]
    >hide those members?
    >
    >Best
    >
    >
    >
    >---
    >Outgoing mail is certified Virus Free.
    >Checked by AVG anti-virus system[/color]
    (http://www.grisoft.com).[color=blue]
    >Version: 6.0.500 / Virus Database: 298 - Release Date:[/color]
    7/10/2003[color=blue]
    >
    >
    >.
    >[/color]

    Comment

    • Jon Skeet

      #3
      Re: Hiding inherited members

      Mike M <mike.miller@bc bskc.com> wrote:[color=blue]
      > I was actually going to ask the same question. I'll give
      > you an example though.
      >
      > If you look at the TrackBar control, there is no Text
      > property because there is no text rendered on the
      > control.[/color]

      But TrackBar *does* have a Text property. I'm not sure why it's not
      document, but it *does* exist:

      using System;
      using System.Windows. Forms;

      public class Test
      {
      static void Main()
      {
      TrackBar tb = new TrackBar();
      tb.Text="hello" ;
      }
      }

      compiles fine.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Mike M

        #4
        Re: Hiding inherited members

        Then it must be hidden. It doesn't show up in the
        intelliSense, which is good enough to avoid confusion.
        The BrowsableAttrib ute just makes it so that it doesn't
        show up in the property browser. I was wondering if the
        ObsoleteAttribu te might do it, but I it doesn't look like
        it.

        [color=blue]
        >-----Original Message-----
        >Mike M <mike.miller@bc bskc.com> wrote:[color=green]
        >> I was actually going to ask the same question. I'll[/color][/color]
        give[color=blue][color=green]
        >> you an example though.
        >>
        >> If you look at the TrackBar control, there is no Text
        >> property because there is no text rendered on the
        >> control.[/color]
        >
        >But TrackBar *does* have a Text property. I'm not sure[/color]
        why it's not[color=blue]
        >document, but it *does* exist:
        >
        >using System;
        >using System.Windows. Forms;
        >
        >public class Test
        >{
        > static void Main()
        > {
        > TrackBar tb = new TrackBar();
        > tb.Text="hello" ;
        > }
        >}
        >
        >compiles fine.
        >
        >--
        >Jon Skeet - <skeet@pobox.co m>
        >http://www.pobox.com/~skeet/
        >If replying to the group, please do not mail me too
        >.
        >[/color]

        Comment

        • Jon Skeet

          #5
          Re: Hiding inherited members

          Mike M <mike.miller@bc bskc.com> wrote:[color=blue]
          > Then it must be hidden. It doesn't show up in the
          > intelliSense, which is good enough to avoid confusion.
          > The BrowsableAttrib ute just makes it so that it doesn't
          > show up in the property browser. I was wondering if the
          > ObsoleteAttribu te might do it, but I it doesn't look like
          > it.[/color]

          I believe you're looking for EditorBrowsable Attribute.

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          • Mike M

            #6
            Re: Hiding inherited members

            Awesome. Thanks. You wouldn't happen to know where I
            can find a nice, neat list of ALL the attributes, would
            you? I found one in help, but either I'm blind or it
            wasn't in the list.
            [color=blue]
            >-----Original Message-----
            >Mike M <mike.miller@bc bskc.com> wrote:[color=green]
            >> Then it must be hidden. It doesn't show up in the
            >> intelliSense, which is good enough to avoid[/color][/color]
            confusion.[color=blue][color=green]
            >> The BrowsableAttrib ute just makes it so that it[/color][/color]
            doesn't[color=blue][color=green]
            >> show up in the property browser. I was wondering if[/color][/color]
            the[color=blue][color=green]
            >> ObsoleteAttribu te might do it, but I it doesn't look[/color][/color]
            like[color=blue][color=green]
            >> it.[/color]
            >
            >I believe you're looking for EditorBrowsable Attribute.
            >
            >--
            >Jon Skeet - <skeet@pobox.co m>
            >http://www.pobox.com/~skeet/
            >If replying to the group, please do not mail me too
            >.
            >[/color]

            Comment

            • Jon Skeet

              #7
              Re: Hiding inherited members

              Mike M <mike.miller@bc bskc.com> wrote:[color=blue]
              > Awesome. Thanks. You wouldn't happen to know where I
              > can find a nice, neat list of ALL the attributes, would
              > you? I found one in help, but either I'm blind or it
              > wasn't in the list.[/color]

              If you look up System.Attribut e in MSDN and then expand "Derived
              Classes" you'll get the immediately derived ones. It's in that list -
              but it's a pretty big list!

              --
              Jon Skeet - <skeet@pobox.co m>
              Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

              If replying to the group, please do not mail me too

              Comment

              • Mike M

                #8
                Re: Hiding inherited members

                Thanks
                [color=blue]
                >-----Original Message-----
                >Mike M <mike.miller@bc bskc.com> wrote:[color=green]
                >> Awesome. Thanks. You wouldn't happen to know where I
                >> can find a nice, neat list of ALL the attributes,[/color][/color]
                would[color=blue][color=green]
                >> you? I found one in help, but either I'm blind or it
                >> wasn't in the list.[/color]
                >
                >If you look up System.Attribut e in MSDN and then[/color]
                expand "Derived[color=blue]
                >Classes" you'll get the immediately derived ones. It's[/color]
                in that list -[color=blue]
                >but it's a pretty big list!
                >
                >--
                >Jon Skeet - <skeet@pobox.co m>
                >http://www.pobox.com/~skeet/
                >If replying to the group, please do not mail me too
                >.
                >[/color]

                Comment

                • Troy Hilbert

                  #9
                  Re: Hiding inherited members

                  Thanks, I was leaning in that direction after spelunking around MSDN. Man
                  I've got much to learn about object oriented design principles. Have any
                  recomendations for neophytes?


                  "Jon Skeet" <skeet@pobox.co m> wrote in message
                  news:MPG.1981ee 762b30e1ab98a14 e@news.microsof t.com...[color=blue]
                  > Troy Hilbert <thilbert@spamf ree.hotmail.com > wrote:[color=green]
                  > > I've created a class derived from NativeWindow. The public methods are
                  > > visible to consumers of my class and I don't wish them to be. How does[/color][/color]
                  one[color=blue][color=green]
                  > > hide those members?[/color]
                  >
                  > You don't. That would violate Liskov's Substitutabilit y Principle, for
                  > a start. I suggest you have a NativeWindow as a field within your class
                  > rather than deriving from it.
                  >
                  > --
                  > Jon Skeet - <skeet@pobox.co m>
                  > http://www.pobox.com/~skeet/
                  > If replying to the group, please do not mail me too[/color]


                  ---
                  Outgoing mail is certified Virus Free.
                  Checked by AVG anti-virus system (http://www.grisoft.com).
                  Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003


                  Comment

                  • Jon Skeet

                    #10
                    Re: Hiding inherited members

                    Troy Hilbert <thilbert@spamf ree.hotmail.com > wrote:[color=blue]
                    > Thanks, I was leaning in that direction after spelunking around MSDN. Man
                    > I've got much to learn about object oriented design principles. Have any
                    > recomendations for neophytes?[/color]

                    Write lots of code, work out what's unpleasant about it, and learn from
                    that. I dare say there are plenty of books that would help out (the
                    Gang of Four "Design Patterns" book, for instance) but experience is
                    the best teacher. There's nothing like doing it wrong to teach you to
                    do it right :)

                    --
                    Jon Skeet - <skeet@pobox.co m>
                    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                    If replying to the group, please do not mail me too

                    Comment

                    Working...