Disable items from an inherited class?

  • Thread starter Thread starter Steven Garrad
  • Start date Start date
S

Steven Garrad

Hi All
I have a custom class that is derived from the PictureBox class. One of the
properties from the PictureBox class is "SizeMode" and in my custom class I
want to disable the user from being able to modify this.

How can I remove this property from my class?

Thanks,
Steve
 
Hi,

Steven Garrad said:
Hi All
I have a custom class that is derived from the PictureBox class. One of
the properties from the PictureBox class is "SizeMode" and in my custom
class I want to disable the user from being able to modify this.

How can I remove this property from my class?

you have to use the "new" keyword to hide the parent implementation:

new public XXXX SizeMode{


I do not remmber that SizeMode returns that's why the XXXX
 
"Ignacio Machin said:
Hi,



you have to use the "new" keyword to hide the parent implementation:

new public XXXX SizeMode{


I do not remmber that SizeMode returns that's why the XXXX

... though there's nothing to stop a user casting your class to a
PictureBox, and using the original SizeMode property.

The only way to completely hide it is to encapsulate a PictureBox
internally, rather than deriving from it.
 
Steven Garrad said:
I have a custom class that is derived from the PictureBox class. One of the
properties from the PictureBox class is "SizeMode" and in my custom class I
want to disable the user from being able to modify this.

How can I remove this property from my class?

Doing so would break Liskov's Substitutability Principle. Basically, if
you don't want type X to have all of the same members available as type
Y, you shouldn't derive type X from type Y in the first place.
 
It's not that I don't want it, but it's that I don't want it to be changed
by the user of the control.
 
Steven Garrad said:
It's not that I don't want it, but it's that I don't want it to be changed
by the user of the control.

That's the same thing, effectively. You want to stop the user from
treating the control as if it were a normal PictureBox, which is what
Liskov's principle is about.
 
Back
Top