0Pricing
Kotlin Multiplatform Academy · درس

رؤية internal مقابل public

التحكم في نطاق واجهة وحدتكم بعناية

رؤية internal مقابل public درس مجاني في Kotlin Multiplatform Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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, " + name

internal 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» مجاني؟

نعم — نص درس «رؤية internal مقابل public» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Kotlin Multiplatform Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.

ماذا ستتعلم في «رؤية internal مقابل public»؟

التحكم في نطاق واجهة وحدتكم بعناية تتمرن على Kotlin Multiplatform Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Kotlin Multiplatform Academy؟

لا تُشترط خبرة سابقة. Kotlin Multiplatform Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «رؤية internal مقابل public»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Kotlin Multiplatform Academy هذا؟

نعم. كل درس في Kotlin Multiplatform Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تصميم API عامة صغيرة
  2. رؤية internal مقابل public
  3. تنظيم الحزم داخل الوحدة
  4. توثيق API للفريقين
← العودة إلى Kotlin Multiplatform Academy