We're finally building a domain model. The domain model includes interfaces for loosely coupling domain objects to persistence. I'm however wondering how coupled the domain model objects should be to each other.
Does Order point to a Customer or to an ICustomer?
This post mentions problems with aggressively de-coupling objects and seems to discourage "going overboard with [interfaces]". I however don't see how I can truly unit test my domain entities unless I can mock the other entities they depend on, which requires loose coupling.
I'm also uncertain about how realistic it is to want a domain model in which pieces could be swapped out.
I don't mind using concrete collaborators in unit tests when the collaborator:
1) Has a comprehensive set of unit tests that clearly specifies its behavior.
2) Isn't difficult to arrange.
3) Doesn't utilize external resources (or break any of these related guidelines).
We do this all the time with framework classes (say, DateTime
or string
) - unless an aggregate's child is unusually complex, you should be able to trust it too.