473,756 Members | 5,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hiding items in base classes

If I have a Class "B" that Inherits Class "A", and my application uses class
"B", is there a way that I can keep from exposing properties, subs, and
events in the Class "A" base class from the application?

For example, if Class "A" has a "StateChang ed" event that I don't want the
application to see, is there a way to hide exposure to that event in Class
"B"?

Thanks for any help.

-Jason

Nov 21 '05 #1
7 1188
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre " <op********@ade lphia.net> wrote in message
news:8e******** ************@ad elphia.com...
If I have a Class "B" that Inherits Class "A", and my application uses
class
"B", is there a way that I can keep from exposing properties, subs, and
events in the Class "A" base class from the application?

For example, if Class "A" has a "StateChang ed" event that I don't want the
application to see, is there a way to hide exposure to that event in Class
"B"?

Thanks for any help.

-Jason

Nov 21 '05 #2
So in Class "B" I would do something like:

Protected Shadows Event StateChanged(Se nder as Object, Args as
StateChangedArg s)

Or

Protected Shadows Property SomeProperty as String

Is that right?

"Marina" <so*****@nospam .com> wrote in message
news:u0******** ******@TK2MSFTN GP10.phx.gbl...
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre " <op********@ade lphia.net> wrote in message
news:8e******** ************@ad elphia.com...
If I have a Class "B" that Inherits Class "A", and my application uses
class
"B", is there a way that I can keep from exposing properties, subs, and
events in the Class "A" base class from the application?

For example, if Class "A" has a "StateChang ed" event that I don't want
the
application to see, is there a way to hide exposure to that event in
Class
"B"?

Thanks for any help.

-Jason


Nov 21 '05 #3
No, that doesn't work, at least for properties.

Class "A" has a property, BindIP that is public and overridable.
Class "B" Inherits class "A", thereby inheriting the BindIP property
My application uses Class "B", and not Class "A"
I don't want my application to know that this BindIP property exists.

If I try to say something like "Protected Overrides Property BindIP as
String", the code produces an error, because Class A defines BindIP as
Public, and I'm trying to redefine it as Protected in Class B.

How can I get around that, and keep it hidden from my application?

-Jason
"Marina" <so*****@nospam .com> wrote in message
news:u0******** ******@TK2MSFTN GP10.phx.gbl...
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre " <op********@ade lphia.net> wrote in message
news:8e******** ************@ad elphia.com...
If I have a Class "B" that Inherits Class "A", and my application uses
class
"B", is there a way that I can keep from exposing properties, subs, and
events in the Class "A" base class from the application?

For example, if Class "A" has a "StateChang ed" event that I don't want
the
application to see, is there a way to hide exposure to that event in
Class
"B"?

Thanks for any help.

-Jason


Nov 21 '05 #4
BindIP has to be declared protected in A.

"OpticTygre " <op********@ade lphia.net> wrote in message
news:mp******** ************@ad elphia.com...
No, that doesn't work, at least for properties.

Class "A" has a property, BindIP that is public and overridable.
Class "B" Inherits class "A", thereby inheriting the BindIP property
My application uses Class "B", and not Class "A"
I don't want my application to know that this BindIP property exists.

If I try to say something like "Protected Overrides Property BindIP as
String", the code produces an error, because Class A defines BindIP as
Public, and I'm trying to redefine it as Protected in Class B.

How can I get around that, and keep it hidden from my application?

-Jason
"Marina" <so*****@nospam .com> wrote in message
news:u0******** ******@TK2MSFTN GP10.phx.gbl...
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre " <op********@ade lphia.net> wrote in message
news:8e******** ************@ad elphia.com...
If I have a Class "B" that Inherits Class "A", and my application uses
class
"B", is there a way that I can keep from exposing properties, subs, and
events in the Class "A" base class from the application?

For example, if Class "A" has a "StateChang ed" event that I don't want
the
application to see, is there a way to hide exposure to that event in
Class
"B"?

Thanks for any help.

-Jason



Nov 21 '05 #5
Which is no good, as I don't have access to the code in A. It is a
pre-compiled dll.

"Marina" <so*****@nospam .com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
BindIP has to be declared protected in A.

"OpticTygre " <op********@ade lphia.net> wrote in message
news:mp******** ************@ad elphia.com...
No, that doesn't work, at least for properties.

Class "A" has a property, BindIP that is public and overridable.
Class "B" Inherits class "A", thereby inheriting the BindIP property
My application uses Class "B", and not Class "A"
I don't want my application to know that this BindIP property exists.

If I try to say something like "Protected Overrides Property BindIP as
String", the code produces an error, because Class A defines BindIP as
Public, and I'm trying to redefine it as Protected in Class B.

How can I get around that, and keep it hidden from my application?

-Jason
"Marina" <so*****@nospam .com> wrote in message
news:u0******** ******@TK2MSFTN GP10.phx.gbl...
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre " <op********@ade lphia.net> wrote in message
news:8e******** ************@ad elphia.com...
If I have a Class "B" that Inherits Class "A", and my application uses
class
"B", is there a way that I can keep from exposing properties, subs, and
events in the Class "A" base class from the application?

For example, if Class "A" has a "StateChang ed" event that I don't want
the
application to see, is there a way to hide exposure to that event in
Class
"B"?

Thanks for any help.

-Jason




Nov 21 '05 #6
No.

"When one type inherits from another, it gets all of the members. You can
hide members in your inherited type, but you can't get rid of them."
- Microsoft documentation.

You can 'hide' members with overriding and shadowing.

Overriding:
"By default, a derived class inherits methods from its base class. If an
inherited property or method needs to behave differently in the derived
class it can be overridden; that is, you can define a new implementation of
the method in the derived class."
- Microsoft documentation.

Shadowing:
"When two programming elements share the same name, one of them can hide -
that is, shadow - the other one. In such a situation, the shadowed element
is not available for reference; instead, when your code uses the shared
name, the Visual Basic compiler resolves it to the shadowing element."
- Microsoft documentation.

"OpticTygre " <op********@ade lphia.net> schreef in bericht
news:8e******** ************@ad elphia.com...
If I have a Class "B" that Inherits Class "A", and my application uses
class
"B", is there a way that I can keep from exposing properties, subs, and
events in the Class "A" base class from the application?

For example, if Class "A" has a "StateChang ed" event that I don't want the
application to see, is there a way to hide exposure to that event in Class
"B"?

Thanks for any help.

-Jason

Nov 21 '05 #7
Then you are probably out of luck.

The best you can do, as far as i know, is make it 'protected shadows'.

However, someone can just do this:

CType(myBInstan ce, A).BindIP

"OpticTygre " <op********@ade lphia.net> wrote in message
news:05******** ************@ad elphia.com...
Which is no good, as I don't have access to the code in A. It is a
pre-compiled dll.

"Marina" <so*****@nospam .com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
BindIP has to be declared protected in A.

"OpticTygre " <op********@ade lphia.net> wrote in message
news:mp******** ************@ad elphia.com...
No, that doesn't work, at least for properties.

Class "A" has a property, BindIP that is public and overridable.
Class "B" Inherits class "A", thereby inheriting the BindIP property
My application uses Class "B", and not Class "A"
I don't want my application to know that this BindIP property exists.

If I try to say something like "Protected Overrides Property BindIP as
String", the code produces an error, because Class A defines BindIP as
Public, and I'm trying to redefine it as Protected in Class B.

How can I get around that, and keep it hidden from my application?

-Jason
"Marina" <so*****@nospam .com> wrote in message
news:u0******** ******@TK2MSFTN GP10.phx.gbl...
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre " <op********@ade lphia.net> wrote in message
news:8e******** ************@ad elphia.com...
> If I have a Class "B" that Inherits Class "A", and my application uses
> class
> "B", is there a way that I can keep from exposing properties, subs,
> and
> events in the Class "A" base class from the application?
>
> For example, if Class "A" has a "StateChang ed" event that I don't want
> the
> application to see, is there a way to hide exposure to that event in
> Class
> "B"?
>
> Thanks for any help.
>
> -Jason
>
>
>



Nov 21 '05 #8

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

Similar topics

6
538
by: harrylmh | last post by:
Hi, I'm learning C# and I just don't quite understand the need for polymorphism. why do we need to use it? how does a base class variable holding a derived class instance do any good? Also, what's the difference between method hiding and overriding when they're both still overriding the base method. Thanks
8
4017
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 would like the base class version to stay there, just be protected instead. I can't make the baseclass version protected because there are times when the baseclass can be used by itself.
6
6663
by: Microsoft | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
7
6625
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
9
4986
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.
8
2632
by: SpotNet | last post by:
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'...
14
2425
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), _
9
2726
by: Andrew Robinson | last post by:
I have class A which inherits from class B. B contains the following virtual method: public virtual List<TSelect() { return new List<T>(); } Is there any way to make private or otherwise hide this method within A so that classes instantiating A don't see it?
11
3050
by: Aflj | last post by:
This code won't compile (two compilers tried, gcc and VC++, both of recent versions, but I don't remember them exactly): class C1 { public: void M1(int i) {} }; class C2: public C1
2
4853
by: developer.new | last post by:
Hi I have a question regarding this concept I learned about recently: Name Hiding. Here's what I've come across: There is a base class with two functions with the same name but different signature. A class inherits publicly from this base class and redefines one of the two functions in the derived class. In that case, a derived class object cannot access the other base class function that it hasn't redefined. I'm posting a code snippet...
0
9487
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, 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...
0
10069
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
9904
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
9735
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...
1
7285
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
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5168
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
3828
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
2697
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.