Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should an Aggregate Root Implement an Interface in Domain-Driven Design

I'm working on a project using both domain-driven design and test-driven development. While reading through the DDD book by Evans, I noticed that he did not define interfaces for aggregate roots in the domain.

If I'm doing both DDD and TDD, should I define interfaces for each aggregate root to make the aggregate root classes easily testable and mockable? If so, should I also define interfaces for each entity contained within the aggregate root as well?

From my searches on Google and StackOverflow, I've found answers that come close to what I'm looking for, but I'm specifically look for advice when doing both DDD and TDD because my assumption is that testability, when doing TDD, might be overlooked in the answers that I've seen so far.

like image 609
Matthew Renze Avatar asked Apr 16 '13 16:04

Matthew Renze


1 Answers

No, test directly against the aggregate. The aggregate itself shouldn't have injected dependencies and if a specific behavior requires a dependency, that should usually be expressed as an interface. An interface on an aggregate is a needless abstraction - there is only one implementation of behaviors - that is the point. Also, take a look at BDD and DDD - Behavior-Driven Development can be seen as an evolution of TDD and aligns nicely with DDD.

like image 126
eulerfx Avatar answered Sep 24 '22 01:09

eulerfx