التدرّب على تصميم OOP
في هذه الصفحة 8 موضوعات
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
نظرة عامة
الموضوعات
- نمذجة مجالات من العالم الحقيقي
- تحديد المسؤوليات
- تجنّب الفئات الضخمة (god classes)
تعلّم أولًا
59 دقيقة قراءة · 6 ساعة تدريب (تقدير)
مخرجات التعلم
- Model a new domain (e.g., a parking garage) from a written description into classes, interfaces, and relationships.
- Assign each responsibility to the class that has the information to fulfil it.
- Spot and split a "god class".
- Explain their design trade-offs to a reviewer.
الدروس
المختبر والتمارين
Lab
BEG-028-LAB1 · Parking garage
Outcomes: 1, 2, 3, 4 · Time: ~6 h Model and implement a garage with levels, spot sizes, vehicles, tickets, and fees. Produce a UML diagram, working code, and a half-page design rationale covering key decisions and trade-offs. Complete a peer review of another learner's design (and receive one). Acceptance: UML + code + a half-page design rationale; peer review completed.
Exercises (assessment: design review using the rubric in إطار التقييم في الدورة, design dimension)
| ID | Outcome | Task |
|---|---|---|
| BEG-028-EX01 | 1 | From the text "A cinema has screens; each screen shows movies at times; customers buy tickets for a showing", list classes, relationships, and one invariant. |
| BEG-028-EX02 | 2 | Decide which class should own: isSoldOut(), price(), canFit(vehicle). Justify each. |
| BEG-028-EX03 | 3 | Given a ShopManager with 12 methods (pricing, stock, email, file saving), propose a split. |
| BEG-028-EX04 | 4 | Write a five-line rationale for your cinema design including one rejected alternative. |
| BEG-028-EX05 | 1, 2 | Spot the premature inheritance: a Vehicle hierarchy with Car, Truck, ElectricTruck, OldTruck where the subclasses differ only by one number. Propose a simpler model. |
أظهر الحلول
- EX01 Classes:
Cinema,Screen,Movie,Showing,Customer,Ticket.Cinema 1—* Screen,Screen 1—* Showing,Showing *—1 Movie,Ticket *—1 Showing. Invariant: a showing cannot sell more tickets than its seats. - EX02
Showing.isSoldOut()(knows seats sold);Showing/aPricePolicyforprice();Spot.canFit(vehicle)(knows its size). Rule: the class with the data does the work. - EX03 For example
PriceCalculator,StockLevel/Inventory,EmailNotifier,ShopRepository, leavingShopas a thin coordinator. - EX04 Should name classes, a main decision (e.g., fee as a separate policy for easy change), and a rejected option with its trade-off.
- EX05 One
Vehicleclass with a size/VehicleTypefield (or a small enum). Inheritance is not needed when only data differs. - The lab is graded with the design dimension of the rubric in إطار التقييم في الدورة.
الاختبار
Outcomes: O1 modeling · O2 responsibilities · O3 god classes · O4 explaining a design.
اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.
الجزء العملي
Design review of the parking garage with the design dimension of إطار التقييم في الدورة, the exercises BEG-028-EX01 to EX05, and a completed peer review. Pass: the design rubric's passing level plus the quiz at 7/10.
أخطاء شائعة
Anemic classes with all logic in one manager; premature inheritance.
التقييم
Design review using the rubric in assessment/framework.md (design dimension).
الصلة بالمسار الوظيفي
Design reviews (MID-066) and DDD (MID-060).