0Pricing
Kotlin Multiplatform Academy · レッスン

機能インターフェースを設計する

プラットフォーム機能の共有契約を定義します

「機能インターフェースを設計する」はCoddyKit上の無料Kotlin Multiplatform Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはKotlin Multiplatform Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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(): String

Group 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. 🎉

よくある質問

「機能インターフェースを設計する」レッスンは無料ですか?

はい。「機能インターフェースを設計する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Kotlin Multiplatform Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。

「機能インターフェースを設計する」で何を学びますか?

プラットフォーム機能の共有契約を定義します ブラウザで直接実行するハンズオンコードでKotlin Multiplatform Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Kotlin Multiplatform Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのKotlin Multiplatform Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「機能インターフェースを設計する」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このKotlin Multiplatform Academyレッスンでコードを書いて実行できますか?

はい。すべてのKotlin Multiplatform Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 機能インターフェースを設計する
  2. デバイス情報のexpect/actual
  3. プラットフォームごとのファイルシステムとパス
  4. プラットフォーム実装を注入する
← Kotlin Multiplatform Academyに戻る