internalとpublicのVisibility
モジュールの公開範囲を意図的に制御します
「internalとpublicのVisibility」はCoddyKit上の無料Kotlin Multiplatform Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはKotlin Multiplatform Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Visibility Controls Access
Kotlin visibility modifiers decide who can call your code. They are how you separate the module's front door from its private rooms.
public Is the Default
If you write nothing, a declaration is public. That means everyone, including both apps, can see and call it from outside the module.
fun greet(name: String) = "Hi, " + nameinternal Means Module-Only
The internal modifier limits a declaration to its own module. Outside code, like the Android or iOS app, simply cannot see it.
internal fun buildHeader(): String = "X-App: 1"private Is Tightest
A private member is visible only inside its file or class. Use it for tiny helpers that nobody else should ever touch.
private fun clamp(x: Int) = x.coerceIn(0, 100)Public Is Your Contract
Treat every public declaration as a promise to callers. Once apps depend on it, changing it can break their builds.
internal for Plumbing
Networking glue, mappers, and helpers are plumbing. Mark them internal so they support your API without becoming part of it.
Default to Closed
Start everything as internal or private, then open only what callers truly need. It is far safer than opening everything by habit.
What Module Means Here
For internal, a module is a set of files compiled together, like your shared Gradle module. The apps are separate modules.
Smaller Surface, Safer Changes
Hiding plumbing shrinks your public surface. With less exposed, you can refactor internals freely without scaring any callers. 🔒
Visibility on Properties Too
Modifiers apply to properties and classes, not just functions. A class can be public while its fields stay private inside.
class Cart {
private var items = 0
val count: Int get() = items
}Internal in Both Apps
Because internal hides things across the module boundary, neither the Android app nor the iOS app sees them, keeping the API tidy.
Quick Check
Let's check how internal behaves.
Recap
public is your contract, internal hides plumbing in the module, and private locks down helpers. Default to closed for a clean API. 🎉
よくある質問
「internalとpublicのVisibility」レッスンは無料ですか?
はい。「internalとpublicのVisibility」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Kotlin Multiplatform Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。
「internalとpublicのVisibility」で何を学びますか?
モジュールの公開範囲を意図的に制御します ブラウザで直接実行するハンズオンコードでKotlin Multiplatform Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Kotlin Multiplatform Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのKotlin Multiplatform Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「internalとpublicのVisibility」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このKotlin Multiplatform Academyレッスンでコードを書いて実行できますか?
はい。すべてのKotlin Multiplatform Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 小さなPublic APIを設計する
- internalとpublicのVisibility
- モジュール内のPackageを整理する
- 両チーム向けにAPIをドキュメント化する