أهداف الدرس
- أن تفصل الواجهة عن البيانات.
| الطبقة | مسؤوليتها |
|---|---|
| الواجهة | ترسم الشاشة وتستقبل اللمس |
| الحالة | تحفظ ما تعرضه الشاشة الآن |
| الخدمات | تتحدّث مع الخادم |
| التخزين | تحفظ على الجهاز ما يلزم دون اتصال |
الشاشة لا تستدعي الخادم مباشرة؛ تطلب من الحالة، والحالة تطلب من الخدمة. فيسهل الاختبار والتغيير.
تمرين
أين تحفظ آخر جدول محاضرات لعرضه دون اتصال؟
الإجابة
في طبقة التخزين، وتعرضه الحالة حتى يصل الجديد.
Lesson goals
- Keep the interface apart from the data.
| Layer | Its job |
|---|---|
| Interface | Draws the screen, takes touches |
| State | Holds what the screen shows now |
| Services | Talks to the server |
| Storage | Keeps on the device what is needed offline |
A screen never calls the server directly; it asks the state, which asks the service. That makes testing and change easy.
Exercise
Where do you keep the last timetable to show offline?
Answer
In the storage layer; the state shows it until the fresh one arrives.
التعليقات / Comments
لا تعليقات بعد. كن أول من يسأل. / No comments yet. Be the first to ask.