By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,697 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,697 IT Pros & Developers. It's quick & easy.

Hiding items in base classes

P: n/a
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 "StateChanged" 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
Share this Question
Share on Google+
7 Replies


P: n/a
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre" <op********@adelphia.net> wrote in message
news:8e********************@adelphia.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 "StateChanged" 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

P: n/a
So in Class "B" I would do something like:

Protected Shadows Event StateChanged(Sender as Object, Args as
StateChangedArgs)

Or

Protected Shadows Property SomeProperty as String

Is that right?

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

"OpticTygre" <op********@adelphia.net> wrote in message
news:8e********************@adelphia.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 "StateChanged" 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

P: n/a
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**************@TK2MSFTNGP10.phx.gbl...
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre" <op********@adelphia.net> wrote in message
news:8e********************@adelphia.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 "StateChanged" 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

P: n/a
BindIP has to be declared protected in A.

"OpticTygre" <op********@adelphia.net> wrote in message
news:mp********************@adelphia.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**************@TK2MSFTNGP10.phx.gbl...
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre" <op********@adelphia.net> wrote in message
news:8e********************@adelphia.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 "StateChanged" 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

P: n/a
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***************@TK2MSFTNGP15.phx.gbl...
BindIP has to be declared protected in A.

"OpticTygre" <op********@adelphia.net> wrote in message
news:mp********************@adelphia.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**************@TK2MSFTNGP10.phx.gbl...
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre" <op********@adelphia.net> wrote in message
news:8e********************@adelphia.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 "StateChanged" 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

P: n/a
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********@adelphia.net> schreef in bericht
news:8e********************@adelphia.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 "StateChanged" 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

P: n/a
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(myBInstance, A).BindIP

"OpticTygre" <op********@adelphia.net> wrote in message
news:05********************@adelphia.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***************@TK2MSFTNGP15.phx.gbl...
BindIP has to be declared protected in A.

"OpticTygre" <op********@adelphia.net> wrote in message
news:mp********************@adelphia.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**************@TK2MSFTNGP10.phx.gbl...
Declare the event as being protected or friend, depending on your exact
needs.

"OpticTygre" <op********@adelphia.net> wrote in message
news:8e********************@adelphia.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 "StateChanged" 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 discussion thread is closed

Replies have been disabled for this discussion.