Practice ยท 1 of 3
Layered Checkout
Assemble a mini layered system in Solution:
- record Order(String id, int cents) (domain)
- record OrderView(String id, String total) (DTO โ total formatted as
"$" + (cents/100) + "." + zeroPadded(cents%100), e.g. $12.05)
- interface OrderRepository { void save(Order o); Order findById(String id); }
- static class InMemoryOrderRepository implements OrderRepository
- static class CheckoutService with constructor (OrderRepository r)
and Order place(String id, int cents): rejects negative cents with
IllegalArgumentException, then saves and returns the order.
- static String viewTotal(int cents) โ the mapping function used by
OrderView.
The controller layer is the test itself: it builds the repo, injects it
into the service, places an order, and maps it to a view.
Difficulty: intermediate
Back to lesson: Practice: Architecture Lab