البنية متعددة الطبقات لـ KMP
افصل طبقات البيانات والنطاق والعرض بوضوح.
البنية متعددة الطبقات لـ KMP درس مجاني في Kotlin Multiplatform Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Kotlin Multiplatform Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
One Codebase, Many Apps
As your KMP app grows, shared code can turn into a tangle. A clear layered architecture keeps every piece in its lane so both apps stay easy to change.
Three Classic Layers
Most KMP apps settle on three layers: data, domain and presentation. Each has one job, and dependencies flow in a single, predictable direction.
The Data Layer
The data layer talks to the outside world: Ktor for HTTP, SQLDelight for storage. It fetches raw bytes and hands clean data upward, hiding the details.
The Domain Layer
The domain layer holds your business rules and models. It knows nothing about HTTP or SQL, so it stays pure, portable and trivially testable.
The Presentation Layer
The presentation layer prepares state for the screen. Shared ViewModels live here, turning domain data into the StateFlow each UI collects.
Dependencies Point Inward
The golden rule: outer layers depend on inner ones, never the reverse. Presentation knows domain; domain knows nothing about either neighbour.
Talk Through Interfaces
Layers connect through interfaces, not concrete classes. Domain declares what it needs; data provides the implementation, so you can swap pieces freely.
interface UserRepository {
suspend fun load(id: String): User
}Models per Layer
Each layer can own its shapes: a network DTO in data, a clean model in domain. Mapping between them keeps API quirks from leaking into your rules.
Why Bother Separating
Separation pays off when requirements shift. Swap a REST API for GraphQL and only the data layer changes; domain and presentation never notice.
It All Lives Shared
Data, domain and presentation can all sit in commonMain. Both Android and iOS reuse the entire stack and only supply the final native screen.
Start Simple
You do not need ten layers on day one. Begin with these three, keep the dependency arrows clean, and let the structure grow only when it earns its keep. 🙂
Quick Check
Which way should dependencies flow between layers?
Recap
You split shared code into data, domain and presentation, pointed dependencies inward, and connected layers through interfaces. Clean lanes, easy changes. 🎉
الأسئلة الشائعة
هل درس «البنية متعددة الطبقات لـ KMP» مجاني؟
نعم — نص درس «البنية متعددة الطبقات لـ KMP» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Kotlin Multiplatform Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.
ماذا ستتعلم في «البنية متعددة الطبقات لـ KMP»؟
افصل طبقات البيانات والنطاق والعرض بوضوح. تتمرن على Kotlin Multiplatform Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Kotlin Multiplatform Academy؟
لا تُشترط خبرة سابقة. Kotlin Multiplatform Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «البنية متعددة الطبقات لـ KMP»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Kotlin Multiplatform Academy هذا؟
نعم. كل درس في Kotlin Multiplatform Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- البنية متعددة الطبقات لـ KMP
- حالات الاستخدام وحدود النطاق
- تقسيم التعليمات البرمجية المشتركة إلى وحدات
- تحديد ما يبقى أصليًا