Renaming Public Properties of Inherited Class

  • Thread starter Thread starter Earl Teigrob
  • Start date Start date
E

Earl Teigrob

Is there a way to rename the public properties of a inherited class? I am
inheriting an asp.net control (class) and am adding addtional functionality.
(in this case, up to 3 borders on an imagebutton control) I would like to
change the name of the BorderColor property to InnerBorderColor because it
would make more sense in the context of this this new control.

Thanks

Earl
 
Hello!

There is no way (AFAIK) to hide inherited members from a superclass. This
defeats the idea of object oriented programming, where you extent classes by
inheriting them and add more members, change the behaviour of inherited
members and so on.

I suggest adding the InnerBorderColor property to your control and take it
from there. The superclass imagebutton control works they way it does, and
you change your own implementation according to your desired functionality.

Basically, think of your new control as an extended imagebutton control,
allowing the developers to do more than what is allowed with the general
imagebutton superclass. If they want to use that interface, they just resort
to casting.

The developers can freely choose which interface (and implementation) to
work with.

Not sure this is what you were looking for though, but I gave it a shot :-)
 
You can create a new method in the inherited class that delegates to the
BorderColor property, but you cannot hide the BorderColor property itself.

I've generally found that if you start asking questions like that, then it
probably means you should be containing the class rather than inheriting it.
 
After I posted this, I tried something to achive what I wanted. It seems to
work. Please advise if you see any problems with this approach. I am
assuming that this is NOT the classic use of OO and inheritance..but is
there any real problem with this approach?

(and BTW, I am not an idealist... I am far more interested it just getting
the job done as simply as possible)

Earl

In the properties below, the private properties hide the inherited
properties from public access. Then I create my new properties and set the
base properties from them...


//Hide Public Property BorderColor
private System.Drawing.Color BorderColor
{
get{
return System.Drawing.Color.Black;
}
}

//Hide Public Property BorderWidth
private System.Web.UI.WebControls.Unit BorderWidth
{
get
{
return System.Web.UI.WebControls.Unit.Pixel(0);
}
}


[Bindable(true),
Category("Apperance"),
DefaultValue("")]
public System.Drawing.Color InnerBorderColor
{
get
{
return base.BorderColor;
}
set
{
base.BorderColor=value;
}
}

[Bindable(true),
Category("Apperance"),
DefaultValue("")]
public System.Web.UI.WebControls.Unit InnerBorderWidth
{
get
{
return base.BorderWidth;
}
set
{
base.BorderWidth=value;
}
}
 
The public property should still be available, even though you declare a
private property with the same name in the inherited class.

If I have the following code:

public class A
{
public string plop
{
get
{
return "";
}
}
}

public class B : A
{
private string plop
{
get
{
return "";
}
}
}

When I instantiate B, I can still access A's plop.

It's possible the designer hides it in the properties though, even though
this would be a bug IMO.

--
John Wood
EMail: first name, dot, last name, at priorganize.com

Earl Teigrob said:
After I posted this, I tried something to achive what I wanted. It seems to
work. Please advise if you see any problems with this approach. I am
assuming that this is NOT the classic use of OO and inheritance..but is
there any real problem with this approach?

(and BTW, I am not an idealist... I am far more interested it just getting
the job done as simply as possible)

Earl

In the properties below, the private properties hide the inherited
properties from public access. Then I create my new properties and set the
base properties from them...


//Hide Public Property BorderColor
private System.Drawing.Color BorderColor
{
get{
return System.Drawing.Color.Black;
}
}

//Hide Public Property BorderWidth
private System.Web.UI.WebControls.Unit BorderWidth
{
get
{
return System.Web.UI.WebControls.Unit.Pixel(0);
}
}


[Bindable(true),
Category("Apperance"),
DefaultValue("")]
public System.Drawing.Color InnerBorderColor
{
get
{
return base.BorderColor;
}
set
{
base.BorderColor=value;
}
}

[Bindable(true),
Category("Apperance"),
DefaultValue("")]
public System.Web.UI.WebControls.Unit InnerBorderWidth
{
get
{
return base.BorderWidth;
}
set
{
base.BorderWidth=value;
}
}

Earl Teigrob said:
Is there a way to rename the public properties of a inherited class? I am
inheriting an asp.net control (class) and am adding addtional functionality.
(in this case, up to 3 borders on an imagebutton control) I would like to
change the name of the BorderColor property to InnerBorderColor because it
would make more sense in the context of this this new control.

Thanks

Earl
 
Very Interesting. From the designer page, the BorderColor property is
hidden, but from the code behind class, it is exposed and works. Rather odd
behavior but it answers my questions. Thanks for your help!

Earl



John Wood said:
The public property should still be available, even though you declare a
private property with the same name in the inherited class.

If I have the following code:

public class A
{
public string plop
{
get
{
return "";
}
}
}

public class B : A
{
private string plop
{
get
{
return "";
}
}
}

When I instantiate B, I can still access A's plop.

It's possible the designer hides it in the properties though, even though
this would be a bug IMO.

--
John Wood
EMail: first name, dot, last name, at priorganize.com

Earl Teigrob said:
After I posted this, I tried something to achive what I wanted. It seems to
work. Please advise if you see any problems with this approach. I am
assuming that this is NOT the classic use of OO and inheritance..but is
there any real problem with this approach?

(and BTW, I am not an idealist... I am far more interested it just getting
the job done as simply as possible)

Earl

In the properties below, the private properties hide the inherited
properties from public access. Then I create my new properties and set the
base properties from them...


//Hide Public Property BorderColor
private System.Drawing.Color BorderColor
{
get{
return System.Drawing.Color.Black;
}
}

//Hide Public Property BorderWidth
private System.Web.UI.WebControls.Unit BorderWidth
{
get
{
return System.Web.UI.WebControls.Unit.Pixel(0);
}
}


[Bindable(true),
Category("Apperance"),
DefaultValue("")]
public System.Drawing.Color InnerBorderColor
{
get
{
return base.BorderColor;
}
set
{
base.BorderColor=value;
}
}

[Bindable(true),
Category("Apperance"),
DefaultValue("")]
public System.Web.UI.WebControls.Unit InnerBorderWidth
{
get
{
return base.BorderWidth;
}
set
{
base.BorderWidth=value;
}
}

Earl Teigrob said:
Is there a way to rename the public properties of a inherited class? I am
inheriting an asp.net control (class) and am adding addtional functionality.
(in this case, up to 3 borders on an imagebutton control) I would like to
change the name of the BorderColor property to InnerBorderColor
because
 
Back
Top