Skip to content

Latest commit

 

History

History
33 lines (26 loc) · 716 Bytes

File metadata and controls

33 lines (26 loc) · 716 Bytes

GCop 540

"Abstract class should not have public constructors. Make it protected instead."

Rule description

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.

Example

public abstract class Foo
{
    public Foo()
    {
        ...
    }
    ...
}

should be 🡻

public abstract class Foo
{
    protected Foo()
    {
        ...
    }
    ...
}