Hiding a member in an extended class...?

  • Thread starter Thread starter SpotNet
  • Start date Start date
S

SpotNet

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' attribute as a work around, but is there a way to make the method
truely hidden? Something similar (I know it's not the same) like VB 6, where
if a method was defined like;

[_AMemberName] where [_ ] would make a method hidden.

===================================================
Eg;

public class TheBase
{
public TheBase() {}

protected virtual Int32 EveryClassUsesThisMethod()
{ return 0;}

protected virtual Int32 OneClassDoesntUseThisMethod() //But all the
others do....!
{ return 0;}
}

public class OneClassExtension: TheBase
{
public OneClassExtension(): base(){}

protected overide Int32 EveryClassUsesThisMethod()
{return base.EveryClassUsesThisMethod();}

private new void OneClassDoesntUseThisMethod(){} //<---A different or
better way of hiding members?
}

Thanks NewsGroup.

Regards,
- SpotNet
 
"SpotNet" <[email protected]> a écrit dans le message de (e-mail address removed)...

| 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?

No, once a member is declared in a base class, it isn't and should never be
possible to hide it in subclasses.

Don't forget, inheritance means that a subclass is *everything* that the
base class is. If you need to hide something, then you have the design
wrong. Sorry to say :-(

Joanna
 
Thank you muchly Joanna, I know what you mean, I thought it was just a
bummer with one method in one class that was an exception...!!!

Thanks again Joanna.

Regards,
- SpotNet

: "SpotNet" <[email protected]> a écrit dans le message de : (e-mail address removed)...
:
: | 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?
:
: No, once a member is declared in a base class, it isn't and should never
be
: possible to hide it in subclasses.
:
: Don't forget, inheritance means that a subclass is *everything* that the
: base class is. If you need to hide something, then you have the design
: wrong. Sorry to say :-(
:
: Joanna
:
: --
: Joanna Carter [TeamB]
: Consultant Software Engineer
:
:
 
SpotNet said:
Thank you muchly Joanna, I know what you mean, I thought it was just a
bummer with one method in one class that was an exception...!!!

Thanks again Joanna.

Regards,
- SpotNet

: "SpotNet" <[email protected]> a écrit dans le message de : (e-mail address removed)...
:
: | 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?
:
: No, once a member is declared in a base class, it isn't and should never
be
: possible to hide it in subclasses.
:
: Don't forget, inheritance means that a subclass is *everything* that the
: base class is. If you need to hide something, then you have the design
: wrong. Sorry to say :-(
:
: Joanna
:
: --
: Joanna Carter [TeamB]
: Consultant Software Engineer
:
:

There is a trick you can do in vb.net (just don't know the keyword in
C#) but there is a way around it if you someone really wants.

in VB.Net we use the keyword "Shadows". You can then use that keyword
and change the scope of the method/property from public to private,
therefor hiding it. If someone casts your class as the base class they
will get access to it though.

Chris
 
"Chris" <[email protected]> a écrit dans le message de (e-mail address removed)...

| There is a trick you can do in vb.net (just don't know the keyword in
| C#) but there is a way around it if you someone really wants.
|
| in VB.Net we use the keyword "Shadows". You can then use that keyword
| and change the scope of the method/property from public to private,
| therefor hiding it. If someone casts your class as the base class they
| will get access to it though.

In C#, this is "new"; but he point still stands that if you have to use it,
you have your design wrong :-(

Joanna
 
Joanna said:
"Chris" <[email protected]> a écrit dans le message de (e-mail address removed)...

| There is a trick you can do in vb.net (just don't know the keyword in
| C#) but there is a way around it if you someone really wants.
|
| in VB.Net we use the keyword "Shadows". You can then use that keyword
| and change the scope of the method/property from public to private,
| therefor hiding it. If someone casts your class as the base class they
| will get access to it though.

In C#, this is "new"; but he point still stands that if you have to use it,
you have your design wrong :-(

Joanna

I agree, it's a hack
 
Thanks Joanna, I know the implementation was not correct a situation that
came from objects being added to the application layer over time. Some
clever cut-pasting, etc everthing now fits into its' place. Just looking for
a quicker fix than that.

Thanks again Joanna.

Regards,
- SpotNet

: "Chris" <[email protected]> a écrit dans le message de : (e-mail address removed)...
:
: | There is a trick you can do in vb.net (just don't know the keyword in
: | C#) but there is a way around it if you someone really wants.
: |
: | in VB.Net we use the keyword "Shadows". You can then use that keyword
: | and change the scope of the method/property from public to private,
: | therefor hiding it. If someone casts your class as the base class they
: | will get access to it though.
:
: In C#, this is "new"; but he point still stands that if you have to use
it,
: you have your design wrong :-(
:
: Joanna
:
: --
: Joanna Carter [TeamB]
: Consultant Software Engineer
:
:
 
: Joanna Carter [TeamB] wrote:
: > "Chris" <[email protected]> a écrit dans le message de : > (e-mail address removed)...
: >
: > | There is a trick you can do in vb.net (just don't know the keyword in
: > | C#) but there is a way around it if you someone really wants.
: > |
: > | in VB.Net we use the keyword "Shadows". You can then use that keyword
: > | and change the scope of the method/property from public to private,
: > | therefor hiding it. If someone casts your class as the base class
they
: > | will get access to it though.
: >
: > In C#, this is "new"; but he point still stands that if you have to use
it,
: > you have your design wrong :-(
: >
: > Joanna
: >
:
: I agree, it's a hack

What's wrong with the hack Chris? Hacks are good, hacks are creative ;~P

- SpotNet
 
"SpotNet" <[email protected]> a écrit dans le message de (e-mail address removed)...

| What's wrong with the hack Chris? Hacks are good, hacks are creative ;~P

You naughty person you! Go stand in the corner and repeat 100 times, "Goto
is evil"

<vbg>

Joanna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top