[.net] C# Protected Inheritance Access

Started by
1 comment, last by phb5000 17 years, 12 months ago
To make my question clear I'm going to start by setting up an example: - I have an abstract class with a certain Property - A Derived class should be able to choose whether, or not, to allow the property to be accessible to everyone using this derived class. abstract class Class1 { protected virtual int TheProperty { base set... base get... } ... } class DerivingClass : Class1 { // The override may be used like this protected override int TheProperty { base set... base get... } // Or this may happen... protected override int TheProperty { something else set... something else get... } } Currently I solved this problem by making The Property protected and virtual in the abstract class. This way, the deriving class will have access to The Property, and IF it wants to, it can override it so that it can be accessible to everyone. However, this doesnt seem very robust since there is a risk of changing the way the property is handled in the derived class. I DO NOT want the property itself to be changed, I just want to change the way the access is "passed along". I hope this is a good enough explanation. Thank you,
Advertisement
Can't be done. The whole point of inheritance and overrides is that while the interface to the class is maintained, you can change the implementation.

Why does it matter that it is impossible to change the implementation? You can always put in your documentation that it usually isn't necessary, but it's best to let the author of that override code decide what is best.
Ok, thanks for the reply.

I was just wondering if it was possible or not.

Thanks,

This topic is closed to new replies.

Advertisement