انتقل إلى المحتوى
أمين أبوزيد
BEG-028

التدرّب على تصميم OOP

  • 5 درس
  • 59 دقيقة قراءة
  • 6 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • نمذجة مجالات من العالم الحقيقي
  • تحديد المسؤوليات
  • تجنّب الفئات الضخمة (god classes)

تعلّم أولًا

59 دقيقة قراءة · 6 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Model a new domain (e.g., a parking garage) from a written description into classes, interfaces, and relationships.
  2. Assign each responsibility to the class that has the information to fulfil it.
  3. Spot and split a "god class".
  4. Explain their design trade-offs to a reviewer.

الدروس

  1. 01من المتطلبات إلى الفئات: مثال محلول12 د قراءة
  2. 02إسناد المسؤوليات12 د قراءة
  3. 03اكتشاف الفئات الضخمة (god classes) وتقسيمها12 د قراءة
  4. 04شرح التصميم11 د قراءة
  5. 05عرض عملي: نمذجة مرآب السيارات انطلاقاً من المتطلبات12 د قراءة

المختبر والتمارين

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)

IDOutcomeTask
BEG-028-EX011From 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-EX022Decide which class should own: isSoldOut(), price(), canFit(vehicle). Justify each.
BEG-028-EX033Given a ShopManager with 12 methods (pricing, stock, email, file saving), propose a split.
BEG-028-EX044Write a five-line rationale for your cinema design including one rejected alternative.
BEG-028-EX051, 2Spot 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/a PricePolicy for price(); Spot.canFit(vehicle) (knows its size). Rule: the class with the data does the work.
  • EX03 For example PriceCalculator, StockLevel/Inventory, EmailNotifier, ShopRepository, leaving Shop as 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 Vehicle class with a size/VehicleType field (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.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1A good first step in modeling from a description is to:O1
  2. 2Nouns in a description become:O1
  3. 3Premature inheritance means:O1
  4. 4Where should Ticket.isExpired(now) live?O2
  5. 5The best home for a behavior is the class that:O2
  6. 6A sign of a god class is:O3
  7. 7An anemic class:O3
  8. 8To split a god class you:O3
  9. 9In a design explanation you should:O4
  10. 10A reviewer finds a flaw in your design. A good response:O4

الجزء العملي

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).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.