473,398 Members | 2,427 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,398 software developers and data experts.

Hiding baseclass members

Hi,

is there a way to hide baseclass members:

class BaseClass {
public BaseClass() {}
public string Get() { return "base"; }
}

class MyClass: BaseClass {
public MyClass() :base() {}
new public string Get() { return "my"; }

}

void Foo() {
MyClass m = new MyClass();
Debug.WriteLine( m.Get() );

BaseClass b = m;
Debug.WriteLine( b.Get() );
}

This code will print "my" and then "base". Is there as way to hide the
BaseClass.Get completely?
thx

Kimmo Laine
Nov 16 '05 #1
4 1414
Kimmo Laine <reply.to@newsgroup> wrote:
is there a way to hide baseclass members:


Well, you can override them instead of hiding them, if they're virtual.
That's the only way though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Not that this is a solution... but I've generally found that when you start
wanting to hide base class methods, you probably need to reconsider the
design. Perhaps you need to use the decorator pattern and delegate the
exposed functions to a member variable?

--
John Wood
EMail: first name, dot, second name at priorganize.com
"Kimmo Laine" <reply.to@newsgroup> wrote in message
news:Or**************@TK2MSFTNGP15.phx.gbl...
Hi,

is there a way to hide baseclass members:

class BaseClass {
public BaseClass() {}
public string Get() { return "base"; }
}

class MyClass: BaseClass {
public MyClass() :base() {}
new public string Get() { return "my"; }

}

void Foo() {
MyClass m = new MyClass();
Debug.WriteLine( m.Get() );

BaseClass b = m;
Debug.WriteLine( b.Get() );
}

This code will print "my" and then "base". Is there as way to hide the
BaseClass.Get completely?
thx

Kimmo Laine

Nov 16 '05 #3
Hi Joe,

in my case they are not virtual - thanks anyway!
Kimmo Laine

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Kimmo Laine <reply.to@newsgroup> wrote:
is there a way to hide baseclass members:


Well, you can override them instead of hiding them, if they're virtual.
That's the only way though.

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

Nov 16 '05 #4
mdb
"Kimmo Laine" <reply.to@newsgroup> wrote in news:OrDRg1bkEHA.3876
@TK2MSFTNGP15.phx.gbl:
Hi,

is there a way to hide baseclass members:

class BaseClass {
public BaseClass() {}
public string Get() { return "base"; }
}
Make your BaseClass.Get() function virtual...

public virtual string Get() { ... }
class MyClass: BaseClass {
public MyClass() :base() {}
new public string Get() { return "my"; }

}


And make your MyClass.Get override it:

public override string Get() { ... }

-mdb
Nov 16 '05 #5

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

Similar topics

11
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...
2
by: Steven T. Hatton | last post by:
I find the surprising. If I derive Rectangle from Point, I can access the members of Point inherited by Rectangle _IF_ they are actually members of a Rectangle. If I have a member of type Point...
8
by: Allen Anderson | last post by:
Just curious if there is a way to hide a public member inherited from another class. I know you can 'new' to give it your own version, but is there a way to make it no longer public period? I...
4
by: Dan | last post by:
I have a need to make a set of classes that all share the same public methods, some implementation and some data. So, I made an abstract base (BaseClass) with an interface (IBaseClass) and a...
7
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...
4
by: Ole Nielsby | last post by:
I'm puzzed by this: /***code begin***/ class X {}; class Y : public X {}; class A { public: virtual void m(X x) {std::wcout << L"A\n";} }; class B : public A {
9
by: Torben Laursen | last post by:
Hi I have a class that I use in Excel to define some custom functions. The problem that I have is that the class also has some building functions that for some reason is there: ToString...
2
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...
162
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...
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
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
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...
0
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...
0
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,...

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.