إبعاد الواجهة عن التعليمات البرمجية المشتركة
رسم الحدود للحفاظ على قابلية نقل الطبقة المشتركة
إبعاد الواجهة عن التعليمات البرمجية المشتركة درس مجاني في Kotlin Multiplatform Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Kotlin Multiplatform Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Draw a Clear Line
Shared code holds logic; the UI stays native. Drawing this line early keeps your common module portable to every target.
Why UI Does Not Belong
Android views and SwiftUI are platform-specific. Putting them in commonMain would break compilation on the other target instantly.
Logic Is the Reusable Part
Calculations, rules and models are what truly repeat across apps. That logic is the high-value code worth sharing once.
Return Data, Not Widgets
Shared functions should hand back plain data, like a total or a label string, never a button or a view.
fun cartLabel(total: Double): String = "Total due: " + totalNo Toasts or Alerts
Showing a message is a UI job. Shared code returns the text to show; each app decides how to display it.
No Colors or Styling
Hex colors and fonts are presentation. Keep styling in each platform's UI so designers can tune apps independently.
Expose State to the UI
Shared code can publish state the UI watches. The apps render it however they like, but never the other way around.
data class CartState(val total: Double, val itemCount: Int)The Dependency Direction
UI depends on shared code, never the reverse. This one-way arrow is what keeps the common module clean and reusable.
Compose MP Is the Exception
Compose Multiplatform can share UI too, but it is opt-in. Your core logic module still stays UI-free and lightweight.
A Quick Smell Test
If a shared file imports a platform UI package, that is a smell. Move that code out into the right app module.
The Payoff
A UI-free shared layer compiles everywhere and adds new targets with ease. Discipline here is what makes KMP pay off. 🚀
Quick Check
What should a shared function return instead of a UI widget?
Recap: Logic Shared, UI Native
You kept widgets, colors and alerts out of common code and let it expose only data the native UIs render. ✅
الأسئلة الشائعة
هل درس «إبعاد الواجهة عن التعليمات البرمجية المشتركة» مجاني؟
نعم — نص درس «إبعاد الواجهة عن التعليمات البرمجية المشتركة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Kotlin Multiplatform Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.
ماذا ستتعلم في «إبعاد الواجهة عن التعليمات البرمجية المشتركة»؟
رسم الحدود للحفاظ على قابلية نقل الطبقة المشتركة تتمرن على Kotlin Multiplatform Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Kotlin Multiplatform Academy؟
لا تُشترط خبرة سابقة. Kotlin Multiplatform Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «إبعاد الواجهة عن التعليمات البرمجية المشتركة»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Kotlin Multiplatform Academy هذا؟
نعم. كل درس في Kotlin Multiplatform Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- حاسبة مشتركة للأسعار والضرائب
- تنسيق العملات والأرقام
- قواعد الأعمال كدوال صِرفة
- إبعاد الواجهة عن التعليمات البرمجية المشتركة