Blog

Decoupled Domain Models

August 26, 2008

On the DDD user group, there has been endless discussions about whether a service or repository can be directly called by classes that are part of the domain model. There is a group of people that believe that this is just fine and then there are a group of people who believe that this violates encapsulation and the very nature of a centralized domain model.

I'm definitely in the second group of people. I believe that domain models can be seen like the kernel of an operating system. It is completely and utterly decoupled from the rest of the application. There are only afferent couplings, no efferent couplings in my DDD book ;-).

However, I do recognize that there are some scenarios where there is a need for calling a service or a repository from the domain model. In fact, I came across this urge in our previous sprint. During the execution of some business logic, its possible that something needs to be resolved by an infrastructure service. How did I keep the domain model decoupled from this infrastructure concern. Domain events!

Udi has written about How to create fully encapsulated Domain Models in the past (make sure to read the comments) and has further refined this approach in one of his latest articles.

I must admit that the solution I applied for achieving multi-threading and dealing with memory leaks is less elegant, but certainly equivalent. But hey, that's what refactoring is for :-).

If you and your team want to learn more about how to write maintainable unit tests and get the most out of TDD practices, make sure to have look at our trainings and workshops or check out the books section. Feel free to reach out at infonull@nullprincipal-itnull.be.

Profile picture of Jan Van Ryswyck

Jan Van Ryswyck

Thank you for visiting my blog. I’m a professional software developer since Y2K. A blogger since Y2K+5. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.

Comments

About

Thank you for visiting my website. I’m a professional software developer since Y2K. A blogger since Y2K+5. Author of Writing Maintainable Unit Tests. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Thinking and learning about all kinds of technologies since forever.

Contact information

(+32) 496 38 00 82

infonull@nullprincipal-itnull.be