I want to know if its possible to hide a base class property from a derived class:
Example:
class BaseDocument
{
public string DocPath{get; set;}
public string DocContent{get; set;}
}
class DerviedDocument: BaseDocument
{
//this class should not get the DocContent property
public Test()
{
DerivedDocument d = new DerivedDocument();
d.//intellisense should only show me DocPath
//I do not want this class to see the DocContent property
}
}
I cannot make the the Docproperty private, because i want to instantiate the BaseDocument class elsewhere and use the property there. Thats will kill the idea of a property anyway.
One way to fix this would be to use a interface, say IDoc, which exposes DocPath property and make both the BaseDocument and DerivedDocument implement the interface. This will break their parent-child relationship though.
I can play with the new and override keywords, but thats not the right way either because the child still 'sees' the property
I tried using the 'sealed' keyword on the DocContent, but that does not seem to solve the problem either.
I understand that it 'breaks' inheritance, but I guess this scenario should be coming up frequently where a child needs to get everything else from the parent but one of two properties and the parent has been declared as a base class.
How can such scenarios be handled gracefully?