在域驱动设计中,您可以在UI中使用域实体吗? [英] In Domain-Driven Design, can you use your domain entities in your UI?

查看:48
本文介绍了在域驱动设计中,您可以在UI中使用域实体吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多领先的DDD项目中,尤其是MVC风格中,我看到UI使用的是反映域实体的显示对象,而不是直接使用这些域对象.显然,这种样式用于分离和分离关注点,我个人更喜欢这种样式.

In many leading DDD projects, especially MVC style, I see the UI using display objects that mirror domain entities, rather than using those domain objects directly. This style is obviously for decoupling and separation of concerns, and I personally prefer this style.

但是我不确定这是DDD的严格原则,还是仅仅是开发人员对DDD的不同解释.

But what I'm not sure of, is whether this a strict tenet of DDD, or whether this is more just different developers' interpretation of it.

您可以直接在UI中使用您的域对象,并且仍然遵循DDD方法吗?

Can you use your domain objects directly in the UI, and still be following the DDD methodology in that act?

还是总是使用显示对象的DDD最佳实践?

Or is it a DDD best practice to always use display objects?

注意:虽然我提到了MVC,但我对是否必须在DDD项目中的几乎所有DDD兼容UI模式中使用显示对象很感兴趣.

Note: While I mention MVC, I'm really interested in whether display objects must be used in almost all DDD compatible UI patterns in a DDD project.

推荐答案

DDD是在设计从建模域开始的软件时的一种思考方式.正如网页所述:

DDD is a way of thinking while designing a software that starts with modelling the domain. As the webpage puts it:

域驱动设计不是 技术或方法论.它是一个 思维方式和一套 优先事项,旨在加快 必须处理的软件项目 具有复杂的域.

Domain-driven design is not a technology or a methodology. It is a way of thinking and a set of priorities, aimed at accelerating software projects that have to deal with complicated domains.

自然而然地遵循此设计模式的一件事是分层体系结构.如 DDD模式摘要

One thing that follows naturally out of this design pattern is a layered architecture. As it is said in DDD Pattern Summaries

将复杂程序划分为 层.在每个内部开发设计 具有凝聚力的层 仅取决于下面的层. 遵循标准的建筑模式 提供与之的松散耦合 上面的图层.集中所有代码 与领域模型相关的一个 层并将其与用户隔离 接口,应用程序和 基础结构代码.域 对象,不承担任何责任 展示自己,存储 自己,管理应用程序 任务等等,可以专注于 表达领域模型.这 允许模型演变成丰富的 足够清晰,足以捕获 基本的业务知识和投入 它可以正常工作.

Partition a complex program into LAYERS. Develop a design within each LAYER that is cohesive and that depends only on the layers below. Follow standard architectural patterns to provide loose coupling to the layers above. Concentrate all the code related to the domain model in one layer and isolate it from the user interface, application, and infrastructure code. The domain objects, free of the responsibility of displaying themselves, storing themselves, managing application tasks, and so forth, can be focused on expressing the domain model. This allows a model to evolve to be rich enough and clear enough to capture essential business knowledge and put it to work.

是否需要显示对象才能执行此操作?那只是实现此目的的一种方法,但可能甚至不是提供松散耦合的最佳方法.举个例子:也许视图层不过是一个Web浏览器和xlt文件,以可视化业务层发出的xml文件?如果有人有更多合适的示例,请添加它们.我的观点是DDD强调了分层体系结构,但并不限于一种可能的解决方案.

Whether you need to have display objects to do that? That is just one way of implementing this, but might not even be the best to provide loose coupling. As for an example: maybe the view layer is but a webbrowser and xlt files to visualize xml files emmitted by the business layer? If anybody has more fitting examples, please add them. My point is that DDD stresses a layered architecture, but does not limit this to one possible solution.

这篇关于在域驱动设计中,您可以在UI中使用域实体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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