473,795 Members | 3,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3349
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 PreFilterProper ties or PostFilterPrope rties 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 ICustomTypeDesc riptor. 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.encor ecredit.com> wrote in message news:un******** *****@TK2MSFTNG P15.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******** ********@tk2msf tngp13.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
3653
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 parent class, and I can't make some "helper" class a friend of the parent class to help in accessing the data.) Problem: I want to derive a class that has a copy constructor that properly copies those data members.
6
1788
by: bazley | last post by:
Why doesn't this work in g++? class Base { public: Base() {} ~Base() {} protected: int foo; }
2
9609
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 define the behavior for most, but not all of its members. The derived classes will define the behavior for the remaining members (the undefined members). I'd like to force the derived classes to implement the undefined members in the base class. I...
4
6745
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 can I completely hide (within the IDE) the members of the base class library i.e. only expose those members that I want exposed? I've tried some methods gleaned by googling for "hiding base class members" which suggested using things like "new" and...
6
3015
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
0
1587
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 the XML. <Base name="cat"/> <Derived name="tabby" inherits="cat"/> Some Derived objects are not fully described in the XML, and their members
10
4702
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 no-parameter constructor for my class with an empty function body. I then instantiated an object and tried printing its values, amazingly the members were already initialized. But how is this possible if I have not included any code for doing so. The...
2
3531
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 function of derived class,do not care the function in the base class. I know I make something wrong here, but i dont kow what the wrong it is? Could some one point out for me? sorry for my poor english.
2
1252
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 the parent class (IWorkerItemBase). How can I hide those members from the parent class in the grid? FYI, my code is below:
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.