As a Java programmer (beginner) introducing myself to C#, I have found you can re-abstract an already implemented method like this (code from this answer)
public class D
{
public virtual void DoWork(int i)
{
// Original implementation.
}
}
public abstract class E : D
{
public abstract override void DoWork(int i);
}
public class F : E
{
public override void DoWork(int i)
{
// New implementation.
}
}
I am aware that this doesn't make the original implementation in class D completely unavailable, only unavailable to subclasses of D that subclass it through subclassing E (the class that re-abstracts the method), and as such shouldn't cause any actual problems if class D was in production.
Still, I find myself wondering, is this not modifying class D's contract, which does NOT specify subclasses MUST override DoWork(int i)
? Is this not contrary to the open/closed principle?
Please note I haven't had any actual or even theoretical code broken by this, and keep in mind I'm only starting with C# so I might be missing something here.