473,699 Members | 2,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hiding a member in an extended class...?


Hello NewsGroup,

I have a base class and six classes that inherit from this base class. All
members in the base class are used in it's extended classes except, in one
of the extended class one member in the base class is not required. Is it
possible to mark a method in the extended class such that it does not appear
in that particular extended class?

I know you can use the 'new' keyword and redefine the method with a
'private' attribute as a work around, but is there a way to make the method
truely hidden? Something similar (I know it's not the same) like VB 6, where
if a method was defined like;

[_AMemberName] where [_ ] would make a method hidden.

=============== =============== =============== ======
Eg;

public class TheBase
{
public TheBase() {}

protected virtual Int32 EveryClassUsesT hisMethod()
{ return 0;}

protected virtual Int32 OneClassDoesntU seThisMethod() //But all the
others do....!
{ return 0;}
}

public class OneClassExtensi on: TheBase
{
public OneClassExtensi on(): base(){}

protected overide Int32 EveryClassUsesT hisMethod()
{return base.EveryClass UsesThisMethod( );}

private new void OneClassDoesntU seThisMethod(){ } //<---A different or
better way of hiding members?
}

Thanks NewsGroup.

Regards,
- SpotNet
Mar 12 '06 #1
8 2629
"SpotNet" <Sp*****@msnews .grp> a écrit dans le message de news:
ei************* *@TK2MSFTNGP12. phx.gbl...

| I have a base class and six classes that inherit from this base class. All
| members in the base class are used in it's extended classes except, in one
| of the extended class one member in the base class is not required. Is it
| possible to mark a method in the extended class such that it does not
appear
| in that particular extended class?

No, once a member is declared in a base class, it isn't and should never be
possible to hide it in subclasses.

Don't forget, inheritance means that a subclass is *everything* that the
base class is. If you need to hide something, then you have the design
wrong. Sorry to say :-(

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Mar 12 '06 #2

Thank you muchly Joanna, I know what you mean, I thought it was just a
bummer with one method in one class that was an exception...!!!

Thanks again Joanna.

Regards,
- SpotNet

"Joanna Carter [TeamB]" <jo****@not.for .spam> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
: "SpotNet" <Sp*****@msnews .grp> a écrit dans le message de news:
: ei************* *@TK2MSFTNGP12. phx.gbl...
:
: | I have a base class and six classes that inherit from this base class.
All
: | members in the base class are used in it's extended classes except, in
one
: | of the extended class one member in the base class is not required. Is
it
: | possible to mark a method in the extended class such that it does not
: appear
: | in that particular extended class?
:
: No, once a member is declared in a base class, it isn't and should never
be
: possible to hide it in subclasses.
:
: Don't forget, inheritance means that a subclass is *everything* that the
: base class is. If you need to hide something, then you have the design
: wrong. Sorry to say :-(
:
: Joanna
:
: --
: Joanna Carter [TeamB]
: Consultant Software Engineer
:
:
Mar 12 '06 #3
SpotNet wrote:
Thank you muchly Joanna, I know what you mean, I thought it was just a
bummer with one method in one class that was an exception...!!!

Thanks again Joanna.

Regards,
- SpotNet

"Joanna Carter [TeamB]" <jo****@not.for .spam> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
: "SpotNet" <Sp*****@msnews .grp> a écrit dans le message de news:
: ei************* *@TK2MSFTNGP12. phx.gbl...
:
: | I have a base class and six classes that inherit from this base class.
All
: | members in the base class are used in it's extended classes except, in
one
: | of the extended class one member in the base class is not required. Is
it
: | possible to mark a method in the extended class such that it does not
: appear
: | in that particular extended class?
:
: No, once a member is declared in a base class, it isn't and should never
be
: possible to hide it in subclasses.
:
: Don't forget, inheritance means that a subclass is *everything* that the
: base class is. If you need to hide something, then you have the design
: wrong. Sorry to say :-(
:
: Joanna
:
: --
: Joanna Carter [TeamB]
: Consultant Software Engineer
:
:


There is a trick you can do in vb.net (just don't know the keyword in
C#) but there is a way around it if you someone really wants.

in VB.Net we use the keyword "Shadows". You can then use that keyword
and change the scope of the method/property from public to private,
therefor hiding it. If someone casts your class as the base class they
will get access to it though.

Chris
Mar 13 '06 #4
"Chris" <no@spam.com> a écrit dans le message de news:
ub************* @TK2MSFTNGP10.p hx.gbl...

| There is a trick you can do in vb.net (just don't know the keyword in
| C#) but there is a way around it if you someone really wants.
|
| in VB.Net we use the keyword "Shadows". You can then use that keyword
| and change the scope of the method/property from public to private,
| therefor hiding it. If someone casts your class as the base class they
| will get access to it though.

In C#, this is "new"; but he point still stands that if you have to use it,
you have your design wrong :-(

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Mar 13 '06 #5
Joanna Carter [TeamB] wrote:
"Chris" <no@spam.com> a écrit dans le message de news:
ub************* @TK2MSFTNGP10.p hx.gbl...

| There is a trick you can do in vb.net (just don't know the keyword in
| C#) but there is a way around it if you someone really wants.
|
| in VB.Net we use the keyword "Shadows". You can then use that keyword
| and change the scope of the method/property from public to private,
| therefor hiding it. If someone casts your class as the base class they
| will get access to it though.

In C#, this is "new"; but he point still stands that if you have to use it,
you have your design wrong :-(

Joanna


I agree, it's a hack
Mar 13 '06 #6

"Chris" <no@spam.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
: Joanna Carter [TeamB] wrote:
: > "Chris" <no@spam.com> a écrit dans le message de news:
: > ub************* @TK2MSFTNGP10.p hx.gbl...
: >
: > | There is a trick you can do in vb.net (just don't know the keyword in
: > | C#) but there is a way around it if you someone really wants.
: > |
: > | in VB.Net we use the keyword "Shadows". You can then use that keyword
: > | and change the scope of the method/property from public to private,
: > | therefor hiding it. If someone casts your class as the base class
they
: > | will get access to it though.
: >
: > In C#, this is "new"; but he point still stands that if you have to use
it,
: > you have your design wrong :-(
: >
: > Joanna
: >
:
: I agree, it's a hack

What's wrong with the hack Chris? Hacks are good, hacks are creative ;~P

- SpotNet
Mar 14 '06 #7

Thanks Joanna, I know the implementation was not correct a situation that
came from objects being added to the application layer over time. Some
clever cut-pasting, etc everthing now fits into its' place. Just looking for
a quicker fix than that.

Thanks again Joanna.

Regards,
- SpotNet

"Joanna Carter [TeamB]" <jo****@not.for .spam> wrote in message
news:us******** ******@tk2msftn gp13.phx.gbl...
: "Chris" <no@spam.com> a écrit dans le message de news:
: ub************* @TK2MSFTNGP10.p hx.gbl...
:
: | There is a trick you can do in vb.net (just don't know the keyword in
: | C#) but there is a way around it if you someone really wants.
: |
: | in VB.Net we use the keyword "Shadows". You can then use that keyword
: | and change the scope of the method/property from public to private,
: | therefor hiding it. If someone casts your class as the base class they
: | will get access to it though.
:
: In C#, this is "new"; but he point still stands that if you have to use
it,
: you have your design wrong :-(
:
: Joanna
:
: --
: Joanna Carter [TeamB]
: Consultant Software Engineer
:
:
Mar 14 '06 #8
"SpotNet" <Sp*****@msnews .grp> a écrit dans le message de news:
OH************* *@tk2msftngp13. phx.gbl...

| What's wrong with the hack Chris? Hacks are good, hacks are creative ;~P

You naughty person you! Go stand in the corner and repeat 100 times, "Goto
is evil"

<vbg>

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Mar 14 '06 #9

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

Similar topics

6
389
by: thechaosengine | last post by:
Hi all, Is there a way to hide a member in a subclass that has been inherited from a base class? Lets leave aside any issues regarding whether its a good idea for a moment. Here's an example similar to what I'm thinking about. Lets suppose I make a class called RoleCollection.
11
4188
by: Lorenzo Villari | last post by:
I premise I don't know C++ well but... I wondered what is this data hiding thing... I mean, if I can look at the header (and i need it beacuse of the class), then what's hidden? Can someone give me an example of something hidden from the user?
6
6659
by: Microsoft | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
7
5172
by: Dennis | last post by:
I have a class named myclass that inheirits from "baseclass". There is a property of "baseclass" that I don't want exposed in the IDE. The MSDN documentation says" "A derived type can hide an inherited member by defining a new member with the same signature. This might be done to make a previously public member private or to define new behavior for an inherited method that is marked as final. " However, this does not hide the...
9
4979
by: bob | last post by:
Hi, I know there exists a good reason why the designers of c++ decided that function hiding should exist. But I don't know why. Can anybody provide a good reason/example of a case where function hiding saves the day. I know there exists one, I'd just like to hear about it. thanks and have a nice day.
39
3180
by: utab | last post by:
Dear all, Is there a clear distinction how to decide which functions to be members of a class and which not How is your attitude (Your general way from your experiences ...) "If the function changes the state of the object, it ought to be a member of that object." Reference Accelerated C++, A. Koenig, page 159.
14
2413
by: Dom | last post by:
Hi all I'm developing a control, and I need to hide some properties to the user. For example, suppose I need Text property to be completely inacessible (from a Form/Code that is into another project/assembly). I tried with attributes: <Browsable(False), _ EditorBrowsable(EditorBrowsableState.Never), _ RefreshProperties(RefreshProperties.Repaint), _
2
7635
by: subramanian100in | last post by:
Is my following understanding correct ? Data abstraction means providing the interface - that is, the set of functions that can be called by the user of a class. Information hiding means mentioning the class members(functions, typedefs, data) under the access control labels : public, protected, private. Encapsulation means providing the implementation of class member
162
10249
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you prefix them with 2 underscores, but I hate prefixing my vars, I'd rather add a keyword before it. Python advertises himself as a full OOP language, but why does it miss one of the basic principles of OOP? Will it ever be added to python?
0
8623
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
9196
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
9054
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...
0
8896
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
7784
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...
1
6546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4390
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...
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.