Avoid abstract classes without abstract or concrete methods

Why you should care

Abstract classes can have public constructors, and this is required in some particular cases. But a public constructor means that the class can be instantiated directly while, by design, abstract classes are aimed to not be instantiable.

How we detect

CAST Highlight counts one occurrence each time an abstract class is defining a public constructor.

abstract class MyClass {
def I = 0

public MyClass() { } // +1 VIOLATION

MyClass(int i) { // +1 VIOLATION (members are public by default)
I = i
}
}

References

5362

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.