---
title: Do Not Ignore Superclass Logic
impact: HIGH
impactDescription: ensures proper inheritance behavior and execution of base class contracts
tags: inheritance, override, superclass, oop, quality, kotlin
---

## Do Not Ignore Superclass Logic

When overriding methods in Kotlin, it is crucial to call the `super` implementation unless you explicitly intend to replace it entirely. Ignoring superclass logic often leads to missing validations, hooks, or lifecycle events defined in the base class.

**Incorrect (ignoring superclass):**

```kotlin
open class BaseService {
    open fun save(entity: Entity) {
        validate(entity)
        db.save(entity)
        logger.info("Entity saved")
    }
}

class UserService : BaseService() {
    override fun save(user: User) {
        // BUG: Skips validation and logging from the base class!
        db.save(user)
    }
}
```

**Correct (calling super):**

```kotlin
class UserService : BaseService() {
    override fun save(user: User) {
        // Perform user-specific logic
        user.lastModified = Instant.now()
        
        // Ensure base class logic (validation, etc.) is executed
        super.save(user)
        
        // Add additional post-save logic
        notifyAdmins(user)
    }
}
```

**Exception (intentional replacement):**

```kotlin
class AdminService : BaseService() {
    // Override: Admins bypass standard validation logic
    override fun save(admin: User) {
        // Intentionally skip super.save()
        db.save(admin)
    }
}
```

**Tools:** Android Studio / IntelliJ IDEA hints, detekt, Code Review
