Design a Capability Interface
Define a shared contract for a platform feature.
Design a Capability Interface is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Some Things Are Platform-Only
Reading the battery level or device model is different on Android and iOS. Shared code still needs a clean way to ask for it. 🔋
Start With the Need, Not the API
Design from what your app actually needs. A simple interface states the capability in plain Kotlin, hiding every platform detail.
interface BatteryInfo {
fun level(): Int
}One Contract, Many Backers
The interface is a promise: anyone who implements it must supply a real battery level. Each platform fulfills that promise its own way.
Keep Methods Tiny
Expose only what callers need. A focused method like level() is far easier to implement per platform than a sprawling, do-everything interface.
Name It for the Domain
Call it BatteryInfo, not AndroidBatteryHelper. A good capability name describes the feature, never the platform behind it.
Return Plain Types
Hand back simple Kotlin types like Int or String. Plain return values keep the interface portable and free of platform classes.
fun model(): StringGroup Related Calls
If several calls belong together, gather them in one interface. Device facts like model and OS version fit naturally side by side.
interface DeviceInfo {
fun model(): String
fun osVersion(): String
}Shared Code Depends on the Type
Your common logic talks only to the interface, never to a concrete class. That keeps business rules testable and platform-agnostic.
class Banner(val info: DeviceInfo)Fakes Become Easy
Because callers depend on the interface, tests can pass a fake that returns canned values. No emulator or real device required. ✅
class FakeDeviceInfo : DeviceInfo {
override fun model() = "Pixel"
override fun osVersion() = "14"
}Avoid Leaking Platform Types
Never put a UIDevice or Android Context into the interface signature. The moment you do, shared code stops compiling on the other target.
Implementations Come Later
The contract is step one. Each platform will supply its own implementation of this interface, which you wire in separately as the next step.
Quick Check
Think about what belongs in the capability contract.
Recap
You learned to design a small, domain-named interface that states a capability, returns plain types, and keeps shared code portable and testable. 🎉
Frequently asked questions
Is the “Design a Capability Interface” lesson free?
Yes — the full text of “Design a Capability Interface” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.
What will I learn in “Design a Capability Interface”?
Define a shared contract for a platform feature. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Kotlin Multiplatform Academy?
No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Design a Capability Interface” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Kotlin Multiplatform Academy lesson?
Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Design a Capability Interface
- expect/actual for Device Info
- File System & Paths per Platform
- Inject Platform Implementations