home / skills / pluginagentmarketplace / custom-plugin-android / fundamentals

fundamentals skill

/skills/fundamentals

This skill helps you master Kotlin fundamentals including syntax, null safety, extension and scope functions, and SOLID practices for robust Android code.

npx playbooks add skill pluginagentmarketplace/custom-plugin-android --skill fundamentals

Review the files below or copy the command above to add this skill to your agents.

Files (6)
SKILL.md
2.0 KB
---
name: fundamentals
description: Master Kotlin syntax, OOP principles, SOLID practices, functional programming, and data structures.
version: "2.0.0"
sasmp_version: "1.3.0"

# Agent Binding
bonded_agent: 01-android-fundamentals
bond_type: PRIMARY_BOND

# Skill Configuration
atomic: true
single_responsibility: Kotlin & OOP fundamentals

# Parameter Validation
parameters:
  topic:
    type: string
    enum: [kotlin, oop, solid, functional, collections]
    required: false
  code_context:
    type: string
    required: false

# Retry Configuration
retry:
  max_attempts: 2
  backoff: exponential
  on_failure: return_basic_example

# Observability
logging:
  level: info
  include: [query, response_time, errors]
---

# Kotlin Fundamentals Skill

## Quick Start

```kotlin
// Variables
val immutable = "constant"
var mutable = "variable"

// Functions
fun greet(name: String): String = "Hello, $name"

// Classes
data class User(val id: Int, val name: String)

// Null safety
val user: User? = null
user?.name // safe call
user?.name ?: "Unknown" // elvis operator
```

## Key Concepts

### Null Safety
- `?` for nullable types
- `!!` for non-null assertion (avoid)
- `?:` elvis operator for defaults
- `?.let { }` for null-safe blocks

### Extension Functions
```kotlin
fun String.isValidEmail(): Boolean = contains("@")
val valid = "[email protected]".isValidEmail()
```

### Scope Functions
- `apply`: Configure object
- `let`: Transform
- `run`: Execute with context
- `with`: Receiver operations
- `also`: Side effects

### Coroutines
```kotlin
viewModelScope.launch {
    val data = withContext(Dispatchers.IO) {
        fetchData()
    }
}
```

## SOLID Principles Summary

1. **SRP**: One responsibility per class
2. **OCP**: Open for extension, closed for modification  
3. **LSP**: Substitutable subtypes
4. **ISP**: Specific interfaces
5. **DIP**: Depend on abstractions

## Learning Resources

- [Kotlin Docs](https://kotlinlang.org/docs/)
- [Kotlin Coroutines](https://kotlinlang.org/docs/coroutines-overview.html)
- [Effective Kotlin](https://kt.academy/)

Overview

This skill teaches core Kotlin fundamentals: syntax, null safety, object-oriented design, SOLID principles, functional patterns, coroutines, and common data structures. It provides concise examples, practical guidelines, and patterns you can apply immediately in Android and backend Kotlin code. The content focuses on readable, maintainable code and hands-on snippets to reinforce learning.

How this skill works

I present short, focused examples and explanations for each concept, including variables, functions, data classes, extension functions, scope functions, and coroutines. For design principles I summarize SOLID with actionable advice and show how to apply them in Kotlin code. Practical snippets and recommended patterns make it easy to try concepts in a project and iterate quickly.

When to use it

  • Learning or refreshing Kotlin basics before starting Android or Kotlin server work
  • When converting Java code to idiomatic Kotlin
  • Designing types and APIs that follow SOLID and OOP principles
  • Implementing concurrency with coroutines in UI or background tasks
  • Writing utility extensions and scope-based transformations to reduce boilerplate

Best practices

  • Prefer val for immutability and var only when state must change
  • Use nullable types and safe calls (?.) instead of !! to avoid runtime crashes
  • Favor small single-responsibility classes and clear interfaces per SOLID
  • Use extension and scope functions to keep code expressive but avoid overuse that harms readability
  • Confine blocking work to Dispatchers.IO and orchestrate concurrency with coroutines and structured concurrency

Example use cases

  • Create a data class for API responses and add extension validators for input
  • Refactor a large class into smaller single-responsibility components following SRP
  • Use coroutines with viewModelScope to fetch data off the UI thread and update state safely
  • Add an isValidEmail extension on String for reusable validation in forms
  • Apply the Elvis operator and let blocks to handle optional fields cleanly

FAQ

Should I avoid all uses of !! in Kotlin?

Yes—prefer safer patterns like nullable types with ?: defaults, safe calls, or explicit checks. Use !! only when you can guarantee non-null and want a deliberate crash for programmer error.

When should I use extension functions vs utility classes?

Use extension functions to add behavior that feels natural on the receiver type and improves readability. Use utility classes when behavior doesn't logically belong to a single type or when you need grouping and dependency injection.