In our codebase, I encountered the following construct: There is a base class B, and then there is a class D which derives from B, but does not override or add any members. In fact, D is completely empty - except for a constructor that initializes some (inherited) properties in a special way.
Consider this contrived C# example:
public class Angle
{
public Angle(float degrees)
{
Degrees = degrees;
}
public float Degrees { get; set; }
}
public class RightAngle : Angle
{
public RightAngle() : base(90)
{
}
}
To me, this seems like a gross violation of OOP principles, but I cannot really pinpoint the issue. Is this a proper use of inheritance or a bad idea? Should I replace the derived class with -for example- a static factory?