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

Can I hide base class properties in a derived class?

Hello!

I would like to hide one property of a base class in a derived class. How
could it be done? I tried to override it with a private property, but that
doesn't seem to do the hiding.

Martin
Jan 23 '06 #1
9 3466
Martin,

I would like to hide one property of a base class in a derived class. How
could it be done? I tried to override it with a private property, but that
doesn't seem to do the hiding.

I assume that you want this for by instance intelligence.

You cannot.

Have a look at the overloaded text property from the picturebox. It does
nothing and still it is there.

Cor
Jan 23 '06 #2
Hi Cor

"Cor Ligthert [MVP]" <no************@planet.nl> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP11.phx.gbl...
Martin,

I would like to hide one property of a base class in a derived class. How
could it be done? I tried to override it with a private property, but
that doesn't seem to do the hiding.

I assume that you want this for by instance intelligence.

You cannot.

Have a look at the overloaded text property from the picturebox. It does
nothing and still it is there.


Ok thanks. I will then satisfy myself with overriding it with a dummy
property who doesn't do any harm.

Martin
Jan 23 '06 #3
"Martin Widmer" <ma***********@businessnet.de> schrieb:
I would like to hide one property of a base class in a derived class. How
could it be done? I tried to override it with a private property, but that
doesn't seem to do the hiding.


Override them with a property which has the same modifier, but specify
'Browsable' and 'EditorBrowsable' attributes on the overriding property.

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

Jan 23 '06 #4
"Martin Widmer" <ma***********@businessnet.de> schrieb

Ok thanks. I will then satisfy myself with overriding it with a
dummy property who doesn't do any harm.


You can also throw a 'NotSupportedException'.
Armin
Jan 23 '06 #5
Martin, this might not apply to your situation, but what about making the
scope of the base property be Friend? This way, they wouldn't be available
outside the assembly, but could be referenced by derived classes within the
assembly.

For example, in my ID3 tag reading library, I have a base ID3TextFrame which
represents all of the frame types that have a Text property. (An ID3 frame
is just a set of values associated to a particular metadata component, like
Artist or Comments.) This allows me to have common code that decodes these
frame types and sets the Text property, even though in most cases, I don't
want the users of the library to access the Text property directly.

So, the base class property (ID3TextFrame.Text) is a Friend and I expose the
value with a public property in a derived class with a name and data type
that is specific to that frame. For example, ID3TrackNumFrame.TrackNum is a
Public Short property.

Again, this may not apply to you, but it's one way to "hide" a base class
property.

Mitchell S. Honnert
www.UltraID3Lib.com
"Martin Widmer" <ma***********@businessnet.de> wrote in message
news:dr**********@nntp.init7.net...
Hello!

I would like to hide one property of a base class in a derived class. How
could it be done? I tried to override it with a private property, but that
doesn't seem to do the hiding.

Martin

Jan 23 '06 #6
Hi Mitchell

"Mitchell S. Honnert" <ne**@REMhonnertOVE.com> schrieb im Newsbeitrag
news:e4**************@TK2MSFTNGP14.phx.gbl...
Martin, this might not apply to your situation, but what about making the
scope of the base property be Friend? This way, they wouldn't be
available outside the assembly, but could be referenced by derived classes
within the assembly.

[...]

I have read abotu this approach already, but my class hierarchy is quite
simple and has only 2 levels, and the base class is not abstract, I also use
it. So I cannot declare the property as friend, if I do so, it would not be
available when I instantiate members of the base class, right?

Thanks a lot

Martin
Jan 24 '06 #7
Hi Herfried

[...]
Override them with a property which has the same modifier, but specify
'Browsable' and 'EditorBrowsable' attributes on the overriding property.


Sounds promising... I am not familiar with attributes of properties in
VB.Net. Could you give me a quick example how to do that in the code?

So far I am overriding with a dummy property like this:

Public Overrides Property Placements() As PlacementsCollection
Get
Throw New System.NotSupportedException
Return Nothing
End Get
Set(ByVal value As PlacementsCollection)
Throw New System.NotSupportedException
End Set
End Property
Martin
Jan 24 '06 #8
"Martin Widmer" <ma***********@businessnet.de> schrieb:
Override them with a property which has the same modifier, but specify
'Browsable' and 'EditorBrowsable' attributes on the overriding property.


Sounds promising... I am not familiar with attributes of properties in
VB.Net. Could you give me a quick example how to do that in the code?


\\\
Imports System.ComponentModel
....

<EditorBrowsable(EditorBrowsableState.Never), Browsable(False)> _
Public Overrides Property Placements() As PlacementsCollection
....
///

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

Jan 24 '06 #9
Herfried, thanks, it's working :)

Martin
Jan 24 '06 #10

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

Similar topics

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: Simon | last post by:
Hi I have developed a custom webcontrol like a Table (A) with a rows collection property (collection derived from CollectionBase) where I put one or more custom webcontrol (B). I need to hide...
4
by: Paul Wu | last post by:
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...
5
by: Chris Szabo | last post by:
Good afternoon everyone. I'm running into a problem deserializing a stream using the XmlSerializer. A stored procedure returns the following from SQL Server: <Student StudentId="1" Status="1"...
3
by: Jordan | last post by:
Suppose I have a system that keeps track of 5 different types of "People". My intent is to have a base Person class, then 5 derived classes for each of the specific person types (e.g., Patient,...
6
by: Taran | last post by:
Hi All, I tried something with the C++ I know and some things just seem strange. consider: #include <iostream> using namespace std;
6
by: --== Alain ==-- | last post by:
Hi, I derived a control to create my custom control. However, some of the control base properties are useless from my point of view and i would like to avoid control user to change them. How...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.