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

How can I hide base class members that are public

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 a blank function
structure but this doesn't apparently work. The only idea I've come up with
is not to inherit the base class but simply create an instance of it and use
that instead and then create only the methods and properties that I need in
my derived class. This at the moment seems to be the most logical solution,
but it also seems like a lot of extra work, does anyone know of a better
way. I basically want it to work like using interfaces, you know, expose and
hide what you want as appropriate.

Thanks

Greg
Nov 15 '05 #1
4 6730
Can you not just make Class1 an interface and make those methods that you
wish not be to re-implemented as "private"? Nonetheless, it really sounds
like you should be moving those common methods to an interface of its own
(e.x ClassInterface) and then have Class1 implement on that common class
(Class1 : ClassInterface).

Hope this helps.
"C-Sharper or C-Hasher, one of the two" <no***@noneofyourbusiness.com> wrote
in message news:OH****************@TK2MSFTNGP12.phx.gbl...
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 a blank function structure but this doesn't apparently work. The only idea I've come up with is not to inherit the base class but simply create an instance of it and use that instead and then create only the methods and properties that I need in my derived class. This at the moment seems to be the most logical solution, but it also seems like a lot of extra work, does anyone know of a better
way. I basically want it to work like using interfaces, you know, expose and hide what you want as appropriate.

Thanks

Greg

Nov 15 '05 #2
Hi Michael,

I don't think I can make Class1 an interface as it is a fully useable class
by itself. Class2 builds upon it and hides some of it's unused features for
this specific application. Your thoughts?

Regards

Greg

"michael" <mp********@sbcglobal.net> wrote in message
news:uw*****************@tk2msftngp13.phx.gbl...
Can you not just make Class1 an interface and make those methods that you
wish not be to re-implemented as "private"? Nonetheless, it really sounds
like you should be moving those common methods to an interface of its own
(e.x ClassInterface) and then have Class1 implement on that common class
(Class1 : ClassInterface).

Hope this helps.
"C-Sharper or C-Hasher, one of the two" <no***@noneofyourbusiness.com> wrote in message news:OH****************@TK2MSFTNGP12.phx.gbl...
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 a blank

function
structure but this doesn't apparently work. The only idea I've come up

with
is not to inherit the base class but simply create an instance of it and

use
that instead and then create only the methods and properties that I need

in
my derived class. This at the moment seems to be the most logical

solution,
but it also seems like a lot of extra work, does anyone know of a better
way. I basically want it to work like using interfaces, you know, expose

and
hide what you want as appropriate.

Thanks

Greg


Nov 15 '05 #3
C-Sharper or C-Hasher, one of the two <no***@noneofyourbusiness.com>
wrote:
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?
You can't. If you don't want people to have access to the base class's
members, don't inherit from it. Have a search for Liskov's
Substitutability Principle for good reasons for this.
I've tried some methods gleaned by googling for "hiding base
class members" which suggested using things like "new" and a blank function
structure but this doesn't apparently work. The only idea I've come up with
is not to inherit the base class but simply create an instance of it and use
that instead and then create only the methods and properties that I need in
my derived class. This at the moment seems to be the most logical solution,
Yup, it is.
but it also seems like a lot of extra work, does anyone know of a better
way. I basically want it to work like using interfaces, you know, expose and
hide what you want as appropriate.


Composition can be a bit of extra work, but gives a lot of flexibility
and can avoid unintended uses of your class.

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

Thanks for clearing that up for me. Some drudge work to do, but not too
much of a problem, at least I don't have to rewrite the implementation
stuff. I have to admit to not having every heard of "Liskov's
Substitutability Principle". Just had a quick look on Google for it and
found a simplified explanation. Which explains it well enough.

Regards

Greg

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
C-Sharper or C-Hasher, one of the two <no***@noneofyourbusiness.com>
wrote:
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?
You can't. If you don't want people to have access to the base class's
members, don't inherit from it. Have a search for Liskov's
Substitutability Principle for good reasons for this.
I've tried some methods gleaned by googling for "hiding base
class members" which suggested using things like "new" and a blank function structure but this doesn't apparently work. The only idea I've come up with is not to inherit the base class but simply create an instance of it and use that instead and then create only the methods and properties that I need in my derived class. This at the moment seems to be the most logical solution,
Yup, it is.
but it also seems like a lot of extra work, does anyone know of a better
way. I basically want it to work like using interfaces, you know, expose

and hide what you want as appropriate.


Composition can be a bit of extra work, but gives a lot of flexibility
and can avoid unintended uses of your class.

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

Nov 15 '05 #5

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

Similar topics

8
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base...
10
by: Bhan | last post by:
Using Ptr of derived class to point to base class and viceversa class base { .... } class derived : public base { .... }
10
by: Ray Z | last post by:
hi, there I build a Class Library, I write a class A to implement interface IA. The problem is when I give the dll file to others, thet can get all information about not only IA, but also A. They...
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
3
by: mfc_mobile | last post by:
Hi, I'm trying to develop a control and want to hide the base class of the control, how do i do that? I want to do something like the follow :- internal class BaseClass { }
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...
7
by: relient | last post by:
Question: Why can't you access a private inherited field from a base class in a derived class? I have a *theory* of how this works, of which, I'm not completely sure of but makes logical sense to...
19
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit...
3
by: Edan | last post by:
I have a base class with protected members (`Base`). The function `MakeBase()` is a member function of another class, that returns a `Base` object initialized with private members of this class. Now...
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: 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
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
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
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,...
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...
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.