عرض عملي: تحويل Shop إلى منافذ ومحوّلات (ports and adapters)
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
refactor Shop live. Prepares MID-059-LAB1.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Start from the layered Shop:
OrderServiceimportsJpaOrderRepositoryand a Stripe client. - Create the
ordersdomain package; moveOrderas a plain class without JPA annotations. - Define outbound ports
OrderRepositoryandPaymentGatewayin the domain; add the inbound portPlaceOrderUseCase. - Write adapters: a JPA adapter with a separate
OrderEntityand mapper, and a payment adapter. - Planned mistake: put
@Entityback on the domainOrder"to save a mapper". Add an ArchUnit test that fails onjakarta.persistenceimports in the domain; remove the annotation and keep the mapper. - Swap in a fake payment adapter; the domain tests still pass untouched.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.