ReSharper suggests changing the accessibility of a public constructor in an abstract class to protected, but it does not state the rationale behind this.
Can you shed some light?
ReSharper suggests changing the accessibility of a public constructor in an abstract class to protected, but it does not state the rationale behind this.
Can you shed some light?
Simply because being public makes no sense in an abstract class. An abstract class by definition cannot be instantiated directly. It can only be instantiated by an instance of a derived type. Therefore the only types that should have access to a constructor are its derived types and hence protected makes much more sense than public. It more accurately describes the accessibility.
It is good OO practice.
public abstract class ExampleAbstractClass
{
protected ExampleAbstractClass()
{
// :::
}
}
You only want the inheriting child classes to have access to the constructor. The only way to do that is by making the constructor protected.
Keep in mind, when you add parameters to these constructors, it is an entirely different discussion.