Single entry point; external code references only the root
Consistency Boundary
One transaction modifies one aggregate
Reference by ID
Other aggregates referenced by ID, not direct object
Small Aggregates
Prefer small to reduce contention
Invariants
Root enforces business invariants on its members
Example: Order Aggregate (Java)
public class Order { // Aggregate Root private final OrderId id; private final CustomerId customerId; // Reference by ID private final List<OrderLine> lines = new ArrayList<>(); private OrderStatus status; public void addLine(ProductId productId, int qty, Money price) { if (status != DRAFT) throw new IllegalStateException("Order locked"); lines.add(new OrderLine(productId, qty, price)); } public Money total() { return lines.stream().map(OrderLine::subtotal).reduce(Money.ZERO, Money::add); }}
3. Entity Pattern
Property
Description
Identity
Has stable unique ID over lifetime
Mutable
State can change; identity does not
Equality
By ID, not by attributes
Examples
Order, Customer, Account
4. Value Object Pattern
Property
Description
No Identity
Defined entirely by its attributes
Immutable
Once created, never modified
Equality
By value (all fields equal)
Examples
Money, Address, DateRange, Coordinates
Example: Money Value Object (Java 21+ record)
public record Money(BigDecimal amount, Currency currency) { public Money { if (amount == null || currency == null) throw new IllegalArgumentException(); } public Money add(Money other) { if (!currency.equals(other.currency)) throw new IllegalStateException("Mismatch"); return new Money(amount.add(other.amount), currency); }}
5. Repository Pattern
Aspect
Detail
Purpose
Abstracts persistence; collection-like interface for aggregates
public class OrderFactory { public Order createFromCart(Cart cart, CustomerId customerId) { Order order = new Order(OrderId.generate(), customerId); cart.items().forEach(i -> order.addLine(i.productId(), i.qty(), i.price())); order.applyDiscounts(discountPolicy.eligible(customerId)); return order; }}
9. Specification Pattern
Aspect
Detail
Purpose
Encapsulate business rule as composable predicate
Operations
and, or, not for combining
Uses
Validation, query criteria, selection rules
Example: Specification
public interface Specification<T> { boolean isSatisfiedBy(T t); }Specification<Order> eligibleForFreeShipping = o -> o.total().amount().compareTo(new BigDecimal("50")) >= 0 && o.shippingAddress().country().equals("US");
10. Ubiquitous Language Pattern
Principle
Detail
Shared Vocabulary
Same terms used by domain experts, devs, code, tests
Per Bounded Context
Each context has its own dictionary
Refactor Together
If language changes, code/docs change too
Tests as Spec
Test names mirror business statements
11. Context Mapping Pattern
Relationship
Description
Partnership
Two contexts coordinate releases
Shared Kernel
Small shared model both depend on (use sparingly)
Customer/Supplier
Upstream serves downstream priorities
Conformist
Downstream conforms to upstream model as-is
Anti-Corruption Layer
Downstream translates from upstream
Open Host Service
Upstream exposes published protocol for many consumers