Demo: redesigning the Order aggregate
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 an anemic Order into an aggregate. Prepares MID-060-LAB1.
Draft outline details
Step by step
- Start from the setter-based
Orderand a service withif (status == ...)checks. - Introduce
OrderId,Money, andOrderLinevalue types; remove setters. - Move rules into methods:
addLine,place,cancel, with status transitions. - Raise
OrderPlacedandOrderCancelledevents and publish them from the application service aftersave. - Planned mistake: hold a full
Customerobject insideOrder. Replace it withCustomerIdand explain why loading and locking grew. - Write one unit test per invariant, with no Spring context.
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.