473,386 Members | 1,609 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,386 software developers and data experts.

Hide members in a derived class

Is there a way to constract a derived class that hides certain public members of a base class ?
With the following code, a class that derives from DerivedClass can still see the member "Name" in the base class. Can anyone provide me with an example that will do what I need?

Public Class BaseClass
Private mName As String = "Bob"
Public Overridable Function Name() As String
Name = mName
End Function
End Class

Public Class DerivedClass : Inherits BaseClass
Private Shadows Function Name() As String
Name = "Joe"
End Function
End Class
--------------------------------
Thanks,
Paul Wu

Nov 21 '05 #1
4 3325
Paul,

No you can't. You will see this behaviour as well in some of the standard controls who derive from control. Some members do just nothing.

I hope this helps anyhow,

Cor
Nov 21 '05 #2
Classes will always have the methods and properties they were created with. You cannot hide these from code but you can hide them from the eyes of your users if you know what you're doing.

In the case of a class that is examined at design-time by the property grid you can hide classes by creating a designer for your class and overriding the PreFilterProperties or PostFilterProperties methods. These take the list of properties obtained by reflection and remove enable you to add or rmove property descriptors. This is how the Browsable attribute works to enable certain properties to be visible at design time.

The trick of overriding the class and marking a property as browseable or not is also a possibility for design-time usage but is IMO not quite so desirable.

If you're code presents properties in some other way at runtime, perhaps through the property grid or some other form of reflection, you can make your class implement ICustomTypeDescriptor. This interface enables you to preemptively filter properties and can be used at runtime without a designer.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Paul Wu" <pw*@spam.encorecredit.com> wrote in message news:un*************@TK2MSFTNGP15.phx.gbl...
Is there a way to constract a derived class that hides certain public members of a base class ?
With the following code, a class that derives from DerivedClass can still see the member "Name" in the base class. Can anyone provide me with an example that will do what I need?

Public Class BaseClass
Private mName As String = "Bob"
Public Overridable Function Name() As String
Name = mName
End Function
End Class

Public Class DerivedClass : Inherits BaseClass
Private Shadows Function Name() As String
Name = "Joe"
End Function
End Class
--------------------------------
Thanks,
Paul Wu

Nov 21 '05 #3
Bob,
In the case of a class that is examined at design-time by the property grid
you can hide >classes by creating a designer etc.


I wrote this in a way like you as well and deleted that again, because it is
for somebody who create classes in my opinion not interesting.

The chalenge is in my opinon to let the members never (directly) been showed
in a derived class . (With directly I mean without casting).

When you have a solution for that, than I will be glad when you can show
that and do I probably miss something.

Cor
Nov 21 '05 #4
The only sensible way to do what you're suggesting is to use the memento
pattern...

Otherwise, the suggestions I made are the only possible alternatives.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Bob,
In the case of a class that is examined at design-time by the property
grid you can hide >classes by creating a designer etc.


I wrote this in a way like you as well and deleted that again, because it
is for somebody who create classes in my opinion not interesting.

The chalenge is in my opinon to let the members never (directly) been
showed in a derived class . (With directly I mean without casting).

When you have a solution for that, than I will be glad when you can show
that and do I probably miss something.

Cor

Nov 21 '05 #5

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

Similar topics

5
by: Suzanne Vogel | last post by:
Hi, Given: I have a class with protected or private data members, some of them without accessor methods. It's someone else's class, so I can't change it. (eg, I can't add accessor methods to the...
6
by: bazley | last post by:
Why doesn't this work in g++? class Base { public: Base() {} ~Base() {} protected: int foo; }
2
by: Dave Veeneman | last post by:
Is is legal to declare abstract members in non-abstract classes? How about non-abstract members in abstract classes? I am writing a base class with three derived classes. The base class will...
4
by: C-Sharper or C-Hasher, one of the two | last post by:
Hi, I have a C# class libary (Class1) which is inherited by another class in a Windows Forms app. I want this other class to implement some, but not all of the features of the base class. How...
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
0
by: Cat | last post by:
I have class Base, and class Derived. I am serializing Derived objects from XML, and these Derived objects are allowed to 'inherit' the values from other named Base objects already defined in...
10
by: Joel | last post by:
Is it true that if we don't specify a default constructor for our class, then the C# compiler provides us with its own that zeroes (or assigns default values) to the data members? I wrote a...
2
by: dolphin | last post by:
Hi everyone . I am confused about the different between override overload and hide. May be I have a wrong opinion, I always think that hide is very similar with override. Both of them call the...
2
by: Curious | last post by:
I have a derived class (DistributionItem) that contains a few members. Now I have a binding list of instances of this class to be displayed in a grid. However, extra columns are displayed from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.