开发者

Is using DAO in domain objects correct?

开发者 https://www.devze.com 2023-01-24 04:44 出处:网络
I found the following in an article: \"DAO classes should never be called directly from the client (Services and other consumer classes). The clients should always call the domain objects which in tur

I found the following in an article: "DAO classes should never be called directly from the client (Services and other consumer classes). The clients should always call the domain objects which in turn should call the DAO's for persisting the data 开发者_如何学Goto the data store. ".

This is not how I have seen things done before when doing DDD. Any thoughts on this?

Thanks


That last sentence you quoted from the article could have been written more clearly. I suspect the author meant (emphasis is my added text):

The clients should always call the domain objects which should call the Repository which in turn should call the DAO's for persisting the data to the data store.


"DAO classes should never be called directly from the client (Services and other consumer classes). The clients should always call the domain objects which in turn should call the DAO's for persisting the data to the data store. "

No, I think that is quite wrong.

Domain objects probably shouldn't reference Repositories, either.

If a domain object needs to collaborate with other domain objects, it can raise domain events or take other domain objects as parameters to methods (in which case, the client/caller retrieves all necessary domain objects through repositories).

0

精彩评论

暂无评论...
验证码 换一张
取 消