Abstract To Concrete

ID

kotlin.abstract_to_concrete

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Kotlin

Tags

best-practice, code-style

Description

Reports abstract class declarations whose body contains no abstract members (no abstract functions and no abstract properties). The abstract modifier on such a class is misleading: subclasses are forced to exist before the type can be instantiated, yet there is nothing for them to provide.

Rationale

// Bad — abstract with no abstract members
abstract class Helper {
    fun greet() = "hi"
}

Marking a class abstract is a contract with subclasses: "you must implement the members I leave open". When that contract has no open members, the modifier just adds friction. Clients must extend the class before they can use it, which encourages tiny pass-through subclasses purely to satisfy the compiler.

Remediation

// Good — no abstract members, so make it concrete
class Helper {
    fun greet() = "hi"
}

// Good — abstract because something is abstract
abstract class Shape {
    abstract fun area(): Double
}

Either drop the abstract modifier or add the abstract members that subclasses are meant to implement. Sealed hierarchies and interfaces are excluded because their semantics differ.