Demo: turning Shop into ports and adapters
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
refactor Shop live. Prepares MID-059-LAB1.
Draft outline details
Step by step
- 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.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.