Visibilidade internal versus pública
Controle deliberadamente a superfície do seu módulo
Visibilidade internal versus pública é uma aula grátis de Kotlin Multiplatform Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Kotlin Multiplatform Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Kotlin Multiplatform Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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. 🎉
Perguntas Frequentes
A aula “Visibilidade internal versus pública” é grátis?
Sim — o texto completo de “Visibilidade internal versus pública” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Kotlin Multiplatform Academy, atualize para CoddyKit PRO. O curso de Kotlin Multiplatform Academy inclui 4 aulas no total.
O que vou aprender em “Visibilidade internal versus pública”?
Controle deliberadamente a superfície do seu módulo Você pratica Kotlin Multiplatform Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Kotlin Multiplatform Academy?
Nenhuma experiência prévia é necessária. Kotlin Multiplatform Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “Visibilidade internal versus pública”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Kotlin Multiplatform Academy?
Sim. Cada aula de Kotlin Multiplatform Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Projete uma API pública pequena
- Visibilidade internal versus pública
- Organize pacotes dentro do módulo
- Documente a API para as duas equipes