This is because you did not mark first method
Write
and
virtual
and the second one as
override
. If you did, it would work as you expected.
You also ignored compiler warning which told you that
Node.Write
hides the inherited method
Write
. If you did not ignore it, you would probably get the clue and understood the problem by yourself.
Now, I think you should get it. The problem itself is fixed, but do I have to explain you the behavior of the code you've shown in your question? It should be apparent from the above paragraph and the warning mentioned above.
[EDIT]
And do you really understand how dynamic dispatch via virtual mechanism and virtual method table really works? I hope you do. The presence of interfaces masks this picture a bit, but it makes no difference, in fact.
By the way, I would advise you do use explicit interface implementation syntax to reduce the chance of confusion. Consider changing the code to this:
public class Document : IStorable
{
public Document(string s) { }
void IStorable.Read() { ImplementRead(); }
void IStorable.Write() { ImplementWrite(); }
internal protected virtual void ImplementRead() { }
internal protected virtual void ImplementWrite() { }
}
Nothing is public, all is explicit, virtual methods are separated from interface implementations. There are some other benefits of explicit syntax.
—SA