473,320 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Not showing Certain members of the inherited class

I am inheriting from a text box control and does not want the client see some
of the methods be invisible to the clients.

Mike
Feb 26 '06 #1
7 1683
Mike9900 <Mi******@discussions.microsoft.com> wrote:
I am inheriting from a text box control and does not want the client see some
of the methods be invisible to the clients.


That breaks Liskov's substitutability rule. If you don't want the
client to be able to treat an instance of your type as a TextBox, you
shouldn't be deriving from TextBox.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 26 '06 #2

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike9900 <Mi******@discussions.microsoft.com> wrote:
I am inheriting from a text box control and does not want the client see
some
of the methods be invisible to the clients.


That breaks Liskov's substitutability rule. If you don't want the
client to be able to treat an instance of your type as a TextBox, you
shouldn't be deriving from TextBox.


In plain english: if it derives from TextBox it IS-A TextBox.

What you want is a UserControl containing only a TextBox and with added
properties events and methods. ( A HAS-A relationship )
Feb 26 '06 #3
I think there is a way to hide some inherited members of a drived class. I
did not mean only a TextBox.
--
Mike
"Nick Hounsome" wrote:

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike9900 <Mi******@discussions.microsoft.com> wrote:
I am inheriting from a text box control and does not want the client see
some
of the methods be invisible to the clients.


That breaks Liskov's substitutability rule. If you don't want the
client to be able to treat an instance of your type as a TextBox, you
shouldn't be deriving from TextBox.


In plain english: if it derives from TextBox it IS-A TextBox.

What you want is a UserControl containing only a TextBox and with added
properties events and methods. ( A HAS-A relationship )

Feb 26 '06 #4
Mike.... basically this approach in general is a no no and will come
back to bite
you. Yes you can do this by throwing an exception but please don't.

http://www.geocities.com/Jeff_Louie/OOP/oop17.htm

You can use contaiment or a wrapper class to achieve your goal.

http://www.geocities.com/Jeff_Louie/OOP/oop7.htm

In fact, you can use a plug in architecture to achieve extensibility
without true
inheritance.

http://www.geocities.com/Jeff_Louie/oop27.htm

Regards,
Jeff
I am inheriting from a text box control and does not want the client

see some
of the methods be invisible to the clients.<

*** Sent via Developersdex http://www.developersdex.com ***
Feb 26 '06 #5
Mike9900 <Mi******@discussions.microsoft.com> wrote:
I think there is a way to hide some inherited members of a drived class. I
did not mean only a TextBox.


No, there isn't. You can override the implementation of virtual methods
and make them throw exceptions, and you can create "new" methods which
"hide" other methods to some extent, but the latter wouldn't stop
someone from doing:

BaseClass f = new DerivedClass();
f.SomeMethod();

in which case the base class SomeMethod is called, rather than the
"hiding" method in DerivedClass.

(If DerivedClass *overrides* SomeMethod, then obviously it's that
overriding version which is called.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 27 '06 #6
I mean not showing it using VS.NET intelli sense. I thought there is an
attribute that let the user not see that method in the intelli sense.
--
Mike
"Jon Skeet [C# MVP]" wrote:
Mike9900 <Mi******@discussions.microsoft.com> wrote:
I think there is a way to hide some inherited members of a drived class. I
did not mean only a TextBox.


No, there isn't. You can override the implementation of virtual methods
and make them throw exceptions, and you can create "new" methods which
"hide" other methods to some extent, but the latter wouldn't stop
someone from doing:

BaseClass f = new DerivedClass();
f.SomeMethod();

in which case the base class SomeMethod is called, rather than the
"hiding" method in DerivedClass.

(If DerivedClass *overrides* SomeMethod, then obviously it's that
overriding version which is called.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Feb 27 '06 #7
If you override the methods of the class, or properties, and decorate
them with the EditorBrowsable attribute, it will hide the member
outside of the assembly in the code completion for VS. If you want to
hide the property from design time, you need to set its Browsable
attribute, which will disable it from the properties window even in its
own assembly. So, if you want to hide the Text property:

[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public override string Text
{
get { return base.Text; }
set { base.Text = value; }
}

Remember, this will hide the property from the properties browser at
design time, but will only hide it from the auto-complete of Visual
Studio when it is outside of the assembly. It is important to note
that the property can still be accessed, but only if one knows that it
exists. I hope this helps.

Abe Heidebrecht

Feb 27 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Carlos Ribeiro | last post by:
I thought about this problem over the weekend, after long hours of hacking some metaclasses to allow me to express some real case data structures as Python classes. I think that this is something...
8
by: Franz Steinhaeusler | last post by:
Hello NG, I want to retrieve the members of a class with a baseclass. But the problem is, how to get the non derived members. class a: def who(self): print "who"
4
by: rob bowley | last post by:
I have a class which inherits from a generated abstract base class. I simply want to hide some fields which are inherited from the base class when it is serialised. I have tried: public...
6
by: rob.bowley | last post by:
I have a class which inherits from a generated abstract base class. I simply want to hide some fields which are inherited from the base class when it is serialised. I have tried: public...
2
by: lovecreatesbeauty | last post by:
I'm disturbed on this question on a long time. I think if I finally get understand it with your kind help, I will get close to a excellent C++ programmer. And I only can rely on your expertise and...
8
by: Larry Lard | last post by:
Today I discovered that a syntax that I thought was forbidden in C# but allowed in VB.NET (and I _don't like_ that it's allowed in VB.NET) is actually allowed in C#. Which confused me. The syntax...
14
by: lovecreatesbea... | last post by:
Could you tell me how many class members the C++ language synthesizes for a class type? Which members in a class aren't derived from parent classes? I have read the book The C++ Programming...
2
by: BeautifulMind | last post by:
Hi, As per the C++ standard, after the compilation of the following class "Test" how many / which members would be generated by the compiler. and actually I am also interested behind the logic...
2
by: eggie5 | last post by:
Hi, I have a class Dog which derives from Animal. Suppose my instance of Dog is bulldog. bulldog has all the members of Animal plus Dog. How can copy just the members from Dog to a new Dog...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.