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 4 6745
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***@noneofyo urbusiness.com> wrote
in message news:OH******** ********@TK2MSF TNGP12.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
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********@sbc global.net> wrote in message
news:uw******** *********@tk2ms ftngp13.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***@noneofyo urbusiness.com>
wrote in message news:OH******** ********@TK2MSF TNGP12.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
C-Sharper or C-Hasher, one of the two <no***@noneofyo urbusiness.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
Substitutabilit y 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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
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
Substitutabilit y 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.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com... C-Sharper or C-Hasher, one of the two <no***@noneofyo urbusiness.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 Substitutabilit y 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.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 class is executed. It
means that three derived classes are pointed to a separated copy of base
class. I do not allow second and third copy of base class to be created,
but it must remain only first copy of base class.
It allows three derived...
|
by: Bhan |
last post by:
Using Ptr of derived class to point to base class and viceversa
class base
{
....
}
class derived : public base
{
....
}
|
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 can even see my protected members of
class A. How could I hide these informations about class A, just give them
the interface informations.
thanks.
|
by: Alex Sedow |
last post by:
Example 1
interface I
{
string ToString();
}
public class C : I
{
public void f()
{
|
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 {
}
| |
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 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
|
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 me. So,
I'm here for an answer (more of a confirmation), hopefully.
First let me say that I know people keep saying; it doesn't work
because the member "is a private". I believe there's more to it than
just simply that...
Theory: You inherit,...
|
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 modify come of
the classes so they match our purpose better - mostly add a few
methods etc.
Example: Open source lib has classes Map and Layer defined. The
relationship between them is one to many.
We created our own versions (inherited) of Map...
|
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 the thing is, I want to extend the functionality of `Base` class. I do that by inheriting `Base` class by `Derived`, but then I can't use `MakeBase()` function. It all makes sense to me, but I don't seem to find an appropriate solution.
Since I...
|
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...
|
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,...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |