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

نظام الوحدات في Java

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

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

نظرة عامة

الموضوعات

  • أساسيات JPMS
  • classpath مقابل module path

تعلّم أولًا

1.5 ساعة تدريب (تقدير)

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

  1. Write module-info.java with requires, exports, and opens.
  2. Explain the classpath vs the module path and strong encapsulation.
  3. Decide whether a Spring service benefits from JPMS, and use alternatives (e.g., ArchUnit) for module boundaries.

الدروس

  1. 01مشكلات classpath التي يحلها JPMS
  2. 02كتابة واصفات الوحدات
  3. 03الانعكاس وopens
  4. 04JPMS عمليًا في الخدمات الخلفية
  5. 05عرض عملي: فرض الحدود باستخدام ArchUnit

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

Lab

MID-010-LAB1 · Boundaries

Outcomes: 1–3 · Time: ~1.5 h Modularize Shop Core with JPMS (descriptor, exported API package, opened model package if needed). Enforce Shop API's feature boundaries with ArchUnit tests. Introduce a forbidden dependency and show the build failing. Acceptance: a forbidden dependency fails the build.

Exercises (assessment: quiz plus lab)

IDOutcomeTask
MID-010-EX011Write a module-info.java for com.shop.core that requires java.sql and exports one package.
MID-010-EX021Add opens ... to for a model package used by Jackson; explain the error without it.
MID-010-EX032Explain classpath vs module path and strong encapsulation in four sentences, with an example of what encapsulation blocks.
MID-010-EX042Compile a class that uses an unexported package from another module; read the error.
MID-010-EX053For Shop API (Spring Boot), argue for or against JPMS and name one alternative.
MID-010-EX063Write an ArchUnit rule: services must not depend on controllers.
أظهر الحلول
  • EX01 module com.shop.core { requires java.sql; exports com.shop.core.api; }
  • EX02 Without opens, reflection throws InaccessibleObjectException for private-member access; add opens com.shop.core.model to com.fasterxml.jackson.databind;.
  • EX03 Classpath: flat, everything public is visible. Module path: only exported packages of required modules are visible. Encapsulation blocks access to internals even if public (and deep reflection unless opened).
  • EX04 The compiler reports the package is not visible or not exported.
  • EX05 Typical answer: against for the Boot service (reflection-heavy, library gaps, high cost); use ArchUnit or build modules for boundaries. A reasoned answer for a library is acceptable.
  • EX06 noClasses().that().resideInAPackage("..service..").should().dependOnClassesThat().resideInAPackage("..controller..") with @AnalyzeClasses (verify against the ArchUnit version).

الاختبار

Outcomes: O1 module descriptors · O2 classpath vs module path · O3 JPMS decision and alternatives.

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

  1. 1Which keyword makes a package available to other modules?O1
  2. 2requires transitive means:O1
  3. 3module-info.java belongs:O1
  4. 4exports com.x.api to com.y means:O1
  5. 5Strong encapsulation means:O2
  6. 6The classpath, compared with the module path, is:O2
  7. 7InaccessibleObjectException at startup usually calls for:O3
  8. 8A frequent reason to avoid JPMS in a Spring Boot service is:O3
  9. 9A cheap tool to enforce package-level boundaries:O3
  10. 10An ArchUnit rule violation will:O3

الجزء العملي

Six exercises MID-010-EX01 to EX06 plus the lab. Pass: at least five exercises correct, eight of ten quiz questions right, and the lab where a forbidden dependency fails the build.

أخطاء شائعة

Adopting JPMS for frameworks that rely on deep reflection without opens.

التقييم

Quiz plus lab.

الصلة بالمسار الوظيفي

Modular monolith boundaries (MID-059).

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