Widoczność internal a public
Świadome kontrolowanie powierzchni modułu
Widoczność internal a public to bezpłatna lekcja Kotlin Multiplatform Academy na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Kotlin Multiplatform Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Kotlin Multiplatform Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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. 🎉
Często zadawane pytania
Czy lekcja „Widoczność internal a public” jest bezpłatna?
Tak — pełny tekst „Widoczność internal a public” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Kotlin Multiplatform Academy, przejdź na CoddyKit PRO. Kurs Kotlin Multiplatform Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Widoczność internal a public”?
Świadome kontrolowanie powierzchni modułu Ćwiczysz Kotlin Multiplatform Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Kotlin Multiplatform Academy?
Nie wymagamy żadnego doświadczenia. Kotlin Multiplatform Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.
Ile czasu zajmuje lekcja „Widoczność internal a public”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Kotlin Multiplatform Academy?
Tak. Każda lekcja Kotlin Multiplatform Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Projektowanie małego publicznego API
- Widoczność internal a public
- Organizowanie pakietów w module
- Dokumentowanie API dla obu zespołów