贫血领域模型与领域模型 [英] anemic domain model versus domain model

查看:119
本文介绍了贫血领域模型与领域模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了此反模式及其在SO上的许多关注之后,再次感到困惑.

Being confused again after reading about this anti-pattern and the many concerns about it here on SO.

如果我有一个域模型并捕获了必须保留在数据传输对象中的数据,那是否会使我的域模型成为数据的包装器?在那种情况下,我将使用贫血领域模型.但是,如果我在该包装器上添加了足够的域逻辑,那么它将在什么时候成为真正的域模型?

If I have a domain model and capture the data that must be persisted in a data transfer object, does that make my domain model a wrapper around the data? In that case I would be using an anemic domain model. But if I add enough domain logic on that wrapper, at what point does it become a real domain model then?

我的印象是,捕获必须在域模型中保留的内容违反了良好实践,并创建了贫血的域模型反模式.但是,如果您使用关系数据库,则无法避免选择出导致对象状态的部分并将其保存.

I get the impression that capturing what must be persisted in a domain model violates good practice and creates the anemic domain model anti-pattern. Yet if you use a relational DB there's no way to avoid to single out the part that makes the state of the object and save it.

由于我对概念非常困惑,因此我不确定我写的内容是否有意义.随时要求澄清.

Since I'm pretty confused about the concepts I'm not sure that what I write makes sense. Feel free to ask clarification.

推荐答案

当包含所有(或大多数)行为时,它成为真实"域模型.构成业务领域的内容(请注意,我强调的是业务逻辑,而不是UI或其他正交问题)

It becomes a 'real' domain model when it contains all (or most) of the behaviour that makes up the business domain (note I'm emphasising business logic, not UI or other orthogonal concerns).

如果您使用的是 Ubiquitous Language (无所不在的语言),并且从您的领域专家那里得到了持续的反馈 ,那么您将知道自己是在正确的轨道上(专家在看到您的域模型时应该点头).如果您没有做这些事情,那么您就没有做DDD( Eric Evans谈论它).

If you're using the Ubiquitous Language, and getting constant feedback from your domain experts, you'll know that you're on the right track (experts should nod when they see your domain model). If you're not doing these things, you're not doing DDD (Eric Evans speak about it).

DTO的要点:不要忽略它们.从实现的角度来看,您将需要它们在层/层之间传递数据.结合DTO和真正的域对象的方式实际上取决于您使用的技术.

Onto the point of DTOs: Don't ignore them. From an implementation perspective, you'll need them to ferry data between layers/tiers. How you combine DTOs and true Domain Objects really depends on the technology you're using.

就像在先前的答案中提到的那样,也许您对数据持久性的关注正在分散您对 true 域建模的注意力...

As alluded to in an earlier answer, maybe your focus on data and persistence is distracting you from true domain modelling...

这篇关于贫血领域模型与领域模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆