Is it advisable to use a βnewβ keyword in a derived interface to provide a more derived return value for a property or method with the same name?
Say I have an IDocument interface:
public interface IDocument { IParagraphs Paragraphs { get; } IRevisions Revisions { get; } IStyles Styles { get; } }
And received one IRtfDocument.
public interface IRtfDocument: IDocument { string Rtf { get; } ... }
I also have more derived interfaces for IParagraphs, IRevisions and IStyles: IRtfParagraphs, IRtfRevisions, IRtfStyles. Many RTF-specific needs led to their creation.
When I refer to paragraphs of an RTF document, I would like them to not pass them to IRtfParagraphs. The same goes for changes and styles. It would also be nice to avoid using both "IRtfParagraphs" and "IParagraphs". So I would like to do this:
public interface IRtfDocument : IDocument { new IRtfParagraphs Paragraphs { get; } new IRtfRevisions Revisions { get; } new IRtfStyles Styles { get; } string Rtf { get; } }
Is this considered good practice? It seems like it fits in this situation, but I wanted to run it for you with C # veterans.
Update: So, I really went ahead and tried to use the βnewβ as described in my interfaces. My RtfDocument class was in need of both the IDocument.Styles property and the IRtfDocument.Styles property. Although I could simply return the IDocument.Styles property to IRtfDocument.Styles, this is not entirely correct, as I am implementing two properties.
The compiler does not seem to take into account the fact that IRtfStyles comes from IStyles, so it insists that I have both. It would be nice if the principle Liskova replacement has allowed me to realize just IRtfDocument.Styles in RtfDocument class.