internal vs public Visibility
Control your module's surface area deliberately.
internal vs public Visibility is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 2 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.
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. 🎉
Frequently asked questions
Is the “internal vs public Visibility” lesson free?
Yes — the full text of “internal vs public Visibility” 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 “internal vs public Visibility”?
Control your module's surface area deliberately. 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 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “internal vs public Visibility” 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 Small Public API
- internal vs public Visibility
- Organize Packages Inside the Module
- Document the API for Both Teams