DDD Newbie question:
I read in a blog somewhere that in a scenario where objects are closely associated with each other in a domain driven design, and where one object based on some complicated business rule is开发者_如何学JAVA responsible for the creation of a dependent object, in such a design the usefulness of dependency injection is very limited.
Would you agree?
No, I wouldn't agree.
The whole purpose of DDD is to arrive at an expressive model that facilitates change. It is accepted as a given that business logic often changes, so the model must be flexible enough to enable a quick change of direction in the face of changing requirements or new insight.
As Uncle Bob writes in Clean Code, the only way to enable a flexible and expressive API that can quickly address unprecedented change is to use loose coupling. Loose coupling is achieved through the Dependency Inversion Principle; from there, the connection to DI follows naturally.
As I read Domain-Driven Design, this was always the underlying motivation behind all the talk about Factories, but I personally find the book a little vague there.
精彩评论