Aggregates & Entities in DDD — Concept Check
Questions on Aggregates & Entities in DDD. An aggregate is a cluster of domain objects treated as a single unit; the aggregate root enforces invariants and is the only object that external code holds references to.
Questions in this quiz
8 questions on Aggregates & Entities in DDD — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer is designing an Order aggregate with Order as the root and OrderLine as an internal entity. Which practice should they follow to maintain DDD principles?
- AHold direct references to Customer objects
- BCreate a repository for OrderLine
- CReference Customer by ID within Order
- DAllow external services to modify OrderLine directly
2.A service is experiencing high contention when accessing a Customer aggregate containing orders, addresses, and payment methods. What is the likely cause?
- AThe network latency is too high
- BThe aggregate is too small, causing fragmentation
- CThe database is not optimized for reads
- DThe aggregate is too large, causing contention
3.A developer wants to enforce business invariants in an Order aggregate. How should they implement this?
- ABy creating a repository for each internal entity
- BUsing a separate service to enforce invariants
- CThrough methods in the aggregate root
- DBy allowing direct modification of internal entities
4.An application service needs to add a line to an order. What is the correct approach?
- AUse a repository to find and modify the OrderLine
- BModify the order's total directly and save
- CLoad the order aggregate, call addLine on the root, then save
- DDirectly modify the OrderLine entity and save
5.A developer mistakenly creates a repository for OrderLine. Why is this incorrect?
- AOrderLine should be accessed via the Order aggregate
- BRepositories should only handle value objects
- COrderLine is not a domain object
- DRepositories are not needed in DDD
6.Which statement about aggregates in DDD is true?
- AAggregates should expose internal entities to external services
- BAggregates should be small to reduce contention
- CAggregates should directly reference other aggregates
- DAggregates should be as large as possible to encapsulate data
7.What happens if an Order aggregate's place method is called with no lines added?
- AAn EmptyOrderException is thrown
- BThe method silently fails
- CThe order is placed with a zero total
- DA TooManyLinesException is thrown
8.A developer believes that referencing aggregates directly improves performance. Why is this incorrect?
- ADirect references improve performance
- BDirect references break consistency boundaries
- CDirect references are needed for event handling
- DDirect references are required for invariants