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

الأنماط المعمارية

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

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

نظرة عامة

الموضوعات

  • الطبقي (Layered)
  • السداسي (Hexagonal)
  • العمارة النظيفة (Clean Architecture)
  • المونوليث المعياري (Modular Monolith)

تعلّم أولًا

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

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

  1. Compare layered, hexagonal (ports and adapters), and clean architecture, and state what each protects.
  2. Restructure a layered service so the domain does not depend on frameworks or infrastructure.
  3. Design a modular monolith with enforced module boundaries and explicit module APIs.
  4. Choose a style for a given team size, domain complexity, and change rate.

الدروس

  1. 01ما الغاية من المعمارية
  2. 02العمارة الطبقية وحدودها
  3. 03العمارة السداسية
  4. 04العمارة النظيفة
  5. 05المونوليث المعياري
  6. 06عرض عملي: تحويل Shop إلى منافذ ومحوّلات (ports and adapters)

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

Lab

MID-059-LAB1 · Hexagonal Shop

Outcomes: 1–3 · Time: ~3 h

  1. Restructure Shop into modules (catalog, orders, inventory, payments), each with api and internal packages.
  2. In orders, move the domain to plain Java with outbound ports OrderRepository and PaymentGateway; implement JPA and payment adapters.
  3. Add ArchUnit tests: the domain has no org.springframework.. or jakarta.persistence.. imports; modules only use each other's api.
  4. Add a second payment adapter (fake) and select it by profile.

Acceptance: the payment adapter can be swapped without touching the domain; ArchUnit tests pass and fail when a violation is introduced.

Exercises (assessment: architecture-style comparison for a scenario; five exercises)

IDOutcomeTask
MID-059-EX011Write one paragraph each on what layered, hexagonal, and clean architecture protect and what they cost.
MID-059-EX022Given a service that injects JpaRepository and RestTemplate into business logic, list the dependencies to invert and name the ports.
MID-059-EX032Write an ArchUnit rule that forbids ..domain.. from depending on org.springframework...
MID-059-EX043Sketch a modular monolith for a booking system with three modules; define each module's public API and what stays internal.
MID-059-EX054A 4-person startup with a changing domain and a 40-person bank team with a stable domain: pick a style for each and justify.
أظهر الحلول
  • EX01 Layered: simplicity, but the domain depends on persistence. Hexagonal: domain isolated behind ports, costs extra mapping. Clean: same protection with an explicit use-case ring, costs more ceremony.
  • EX02 Invert: OrderRepository and PaymentGateway (outbound ports in the domain); adapters implement them; the service depends only on the ports.
  • EX03 noClasses().that().resideInAPackage("..domain..").should().dependOnClassesThat().resideInAPackage("org.springframework..") and .check(importedClasses).
  • EX04 For example catalog, booking, payments; each exposes an api interface plus DTOs/events; entities, repositories, and mappers are package-private.
  • EX05 Startup: modular monolith with a light hexagonal core (cheap to change, few people). Bank: hexagonal or clean modular monolith with enforced boundaries; justify by team size, complexity, and change rate. Any justified answer using those three drivers is acceptable.
  • Outcome 3 is also checked by the lab (ArchUnit and module APIs).

الاختبار

Outcomes: O1 compare styles · O2 isolate the domain · O3 modular monolith · O4 choose a style.

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

  1. 1In hexagonal architecture, who owns a port interface?O1
  2. 2The dependency rule says source dependencies point:O1
  3. 3A main weakness of classic layering is:O1
  4. 4Which import should the domain package NOT contain?O2
  5. 5Swapping the payment provider should require changes in:O2
  6. 6A boundary in a modular monolith is reliable when:O3
  7. 7Modules in a modular monolith should:O3
  8. 8Interfaces for every class "just in case" is:O2
  9. 9A small team with an unclear, fast-changing domain should usually start with:O4
  10. 10Which driver is NOT central when choosing a style?O4

الجزء العملي

Five exercises MID-059-EX01 to EX05 plus the lab. Pass: at least four exercises correct (including EX05 with the three drivers named), ArchUnit tests passing, and the payment adapter swapped without domain changes.

أخطاء شائعة

Interfaces for everything with no boundary meaning; modules that share database tables freely.

التقييم

Architecture-style comparison for a scenario.

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

Architectural decomposition (SRC-008).

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