Hide base mambers in an inherited class

  • Thread starter Thread starter owingruters
  • Start date Start date
O

owingruters

Hi all,

I'm trying to hide a member from a base class, like so :
public class class1
{
public class1()
{
}
public int i;
}

public class class2 : class1
{
public class2()
{
}
private new int i;
}

This article :
http://msdn.microsoft.com/library/d...en-us/csspec/html/vclrfcsharpspec_3_7_1_2.asp
, like others, states that now, class2 shouldn't have a property i.

Unfortunatelly, it still does.

My goal eventually is to create a custom user control inherited from
CustomValidator that doen not has a ServerValidate event.

Any ideas on how you cab hide properties and events?,
Greetz,
Owin
Amsterdam
 
owingruters said:
I'm trying to hide a member from a base class

Bad idea.
, like so :
public class class1
{
public class1()
{
}
public int i;
}

public class class2 : class1
{
public class2()
{
}
private new int i;
}

This article :
http://msdn.microsoft.com/library/default.asp?url=
/library/en-us/csspec/html/vclrfcsharpspec_3_7_1_2.asp
, like others, states that now, class2 shouldn't have a property i.

Unfortunatelly, it still does.

Actually, it doesn't - it doesn't have any properties. It still has a
publically available i variable, however.

Name hiding doesn't actually make anything unavailable, it just changes
how you have to access the member in question.
My goal eventually is to create a custom user control inherited from
CustomValidator that doen not has a ServerValidate event.

You won't be able to do that, and a good job too - it would break the
Liskov Substitutability Rule. It sounds like you might want to
encapsulate CustomValidator instead of inheriting from it.
 
Hi Jon,

Thanx for answering!
I understand what u mean, so I'll just leave the ServerValidate event
available for my users!

Owin
 

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